Author |
|
Doug22
Joined: 02 Jun 2013 Posts: 57 Location: Houston TX
|
Posted: Fri 11 Sep '15 15:02 Post subject: redirecting from one page to the same page |
|
|
Advice needed. I have my .htaccess set up to direct everyone coming from "thatsite.com" to my archive page -- archive.htm, no matter where they were trying to go.
Code: | RewriteEngine on
RewriteCond %{HTTP_REFERER} thatsite\.com [NC,OR]
RewriteRule .* http://mysite.com/archive.htm [R=302,L] |
This has the desired effect, but when they come in already wanting to go to my archive page, I get long strings of identical 302s in my logs. About twenty of them for each request! Apache seems to have some confusion about redirecting from one page to the same page.
What should I be doing in my .htaccess file to avoid getting these long strings of 302s? |
|
Back to top |
|
Doug22
Joined: 02 Jun 2013 Posts: 57 Location: Houston TX
|
Posted: Fri 11 Sep '15 19:45 Post subject: |
|
|
Wow. I tried
Code: | RewriteRule ^(.*)$ http://mysite.com/$1 [R=301,L] |
and that fails in a massively more messy way. |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Fri 11 Sep '15 22:40 Post subject: |
|
|
wouldn't just adding another condition saying if it's not already archive.html then go ahead and rewrite/redirect the url? |
|
Back to top |
|
Doug22
Joined: 02 Jun 2013 Posts: 57 Location: Houston TX
|
Posted: Fri 11 Sep '15 23:01 Post subject: |
|
|
Quote: | wouldn't just adding another condition saying if it's not already archive.html then go ahead and rewrite/redirect the url? |
I guess that makes sense. How exactly do you do that? |
|
Back to top |
|
Doug22
Joined: 02 Jun 2013 Posts: 57 Location: Houston TX
|
Posted: Sat 12 Sep '15 17:01 Post subject: |
|
|
I've established that this doesn't work.
Code: | RewriteCond %{HTTP_REFERER} thatsite\.com [NC]
RewriteCond %{REQUEST_URI} !=%{/archive.htm} [NC]
RewriteRule .* http://mysite.com/archive.html [R=302,L]
|
So I'd really appreciate some guidance here. |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Sun 13 Sep '15 4:25 Post subject: |
|
|
Curious, why are you using %{HTTP_REFERER} instead of %{HTTP_HOST}? If I use my bookmark to thatsite.com/index.php?a=123 for example there will be no referer accompanying the request so it will fail there. |
|
Back to top |
|
Doug22
Joined: 02 Jun 2013 Posts: 57 Location: Houston TX
|
Posted: Sun 13 Sep '15 5:35 Post subject: |
|
|
I'm sorry, but I use HTTP_REFERER exclusively in several tests I do in my .htaccess, and it always works for what I want to do. So I'm not sure I understand your point about HTTP_HOST.
When I just send all requests from thatsite.com to a 403, as in
Code: | RewriteCond %{HTTP_REFERER} thatsite\.com [NC]
RewriteRule .* - [F] |
it works each and every time using HTTP_REFERER. I'm trying to do something a little more organized now by sending it to a specific page. The issue here is not recognizing the referer, but in where I want to send those requests.
I'm not sure we're getting very far here. |
|
Back to top |
|
Steffen Moderator
Joined: 15 Oct 2005 Posts: 3093 Location: Hilversum, NL, EU
|
Posted: Sun 13 Sep '15 15:02 Post subject: |
|
|
Did you tried:
RewriteCond %{HTTP_REFERER} thatsite\.com [NC]
RewriteCond %{REQUEST_URI} !=/archive.htm [NC]
RewriteRule .* http://mysite.com/archive.html [R=302,L]
or
RewriteCond %{HTTP_REFERER} thatsite\.com [NC]
RewriteCond %{REQUEST_URI} !^/archive.htm$ [NC]
RewriteRule .* http://mysite.com/archive.html [R=302,L]
or
RewriteCond %{HTTP_REFERER} thatsite\.com [NC]
RewriteCond %{REQUEST_URI} !archive.htm [NC]
RewriteRule .* http://mysite.com/archive.html [R=302,L]
? |
|
Back to top |
|
Doug22
Joined: 02 Jun 2013 Posts: 57 Location: Houston TX
|
Posted: Mon 14 Sep '15 0:30 Post subject: |
|
|
Code: | RewriteCond %{HTTP_REFERER} thatsite\.com [NC]
RewriteCond %{REQUEST_URI} !=/archive.htm [NC]
RewriteRule .* http://mysite.com/archive.html [R=302,L] |
Trying this code above, coming from thatsite.com, and asking for archive.htm from there, my system hands back a bizarre recursive-looking redirect that looks like this
http://mysite.com/archive.htm/archive.htm/archive.htm/archive.htm/archive.htm/archive.htm.....
Needless to say, that results in a redirect error.
Code: | RewriteCond %{HTTP_REFERER} thatsite\.com [NC]
RewriteCond %{REQUEST_URI} !^/archive.htm$ [NC]
RewriteRule .* http://mysite.com/archive.html [R=302,L] |
does the same, as does
Code: | RewriteCond %{HTTP_REFERER} thatsite\.com [NC]
RewriteCond %{REQUEST_URI} !archive.htm [NC]
RewriteRule .* http://mysite.com/archive.html [R=302,L]
|
So what tests should I try to figure this out? |
|
Back to top |
|