logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: redirecting from one page to the same page
Author
Doug22



Joined: 02 Jun 2013
Posts: 53
Location: Houston TX

PostPosted: Fri 11 Sep '15 15:02    Post subject: redirecting from one page to the same page Reply with quote

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: 53
Location: Houston TX

PostPosted: Fri 11 Sep '15 19:45    Post subject: Reply with quote

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

PostPosted: Fri 11 Sep '15 22:40    Post subject: Reply with quote

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: 53
Location: Houston TX

PostPosted: Fri 11 Sep '15 23:01    Post subject: Reply with quote

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: 53
Location: Houston TX

PostPosted: Sat 12 Sep '15 17:01    Post subject: Reply with quote

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

PostPosted: Sun 13 Sep '15 4:25    Post subject: Reply with quote

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: 53
Location: Houston TX

PostPosted: Sun 13 Sep '15 5:35    Post subject: Reply with quote

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: 3059
Location: Hilversum, NL, EU

PostPosted: Sun 13 Sep '15 15:02    Post subject: Reply with quote

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: 53
Location: Houston TX

PostPosted: Mon 14 Sep '15 0:30    Post subject: Reply with quote

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


Reply to topic   Topic: redirecting from one page to the same page View previous topic :: View next topic
Post new topic   Forum Index -> Apache