Forum Moderators: phranque

Message Too Old, No Replies

Is my regexp right in this?

         

PaulLee

8:52 am on Jul 10, 2011 (gmt 0)

10+ Year Member



Hi,
I'm getting quite a sizeable server hit from another forum
and, for reasons best known to me, I want to redirect it
to another page.
I don't know much about editing the .htaccess file, though I
have done it before to redirect a 404 to a custom error page
but in this case I want it to redirect based on HTTP_REFERRER.
I've tried it below and it doesn't work, and I suspect that
the regexp is wrong - it looks right to me, but I think I'm
missing something. Basically, anything from x-y.com (eg
x-y.com\forums , x-y.com\welcome.php etc.) to go
[z.com...]

I haven't anchored the x-y.com name as I sometimes see it with and without the www prefix.

Below is my .htaccess file, including all the gubbins put in there
by my ISP.

Many thanks in anticipation

Paul
--


# -FrontPage-

ErrorDocument 404 /missing.html

RewriteEngine On
RewriteCond %{HTTP_REFERER} x\-y\.com [NC]
RewriteRule .* http://www.z.com/index.php#getlost [L]

IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>

wilderness

3:34 pm on Jul 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



this won't work

#getlost

g1smd

6:32 pm on Jul 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Once you redirect the user, the new request will again match all conditions in your rule and the user will be redirected again.

Five seconds spent looking at the logs for the Live HTTP Headers extension for Firefox will confirm this.

lucy24

8:59 pm on Jul 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Once you redirect the user, the new request will again match all conditions in your rule and the user will be redirected again.

You could add a line to exclude requests for the "getlost" page. But, come to think of it, the given code is functionally identical to what many people use in their hotlinking routines: if the referer is anything other than {approved list of Good Guys} then you go to

RewriteRule \.(jpe?g|gif|png)$ pictures/hotlink.png [NC,L]

Why doesn't that keep going around in circles?