Forum Moderators: phranque

Message Too Old, No Replies

Re-direct Search Engine traffic to another page on the same site probl

Problem with .htaccess rewriterule http_referer

         

andy2005

10:47 am on May 29, 2007 (gmt 0)

10+ Year Member



Hi,

Im just have gone through 100s of post and still I can't find out why my redirect script doesn't work ok. Anyone that can help me out here please?

RewriteBase /
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^.*yahoo.*$ [OR]
RewriteCond %{HTTP_REFERER} ^.*google.*$ [OR]
RewriteCond %{HTTP_REFERER} ^.*msn.*$
RewriteRule ^$ http://www.example.com/newdirectory/newpage.html [R,L]

I have placed the above in an .htaccess file in the root of my domain. But each time I got to http://www.example.com I end up in http://www.example.com/newdirectory/newpage.html and it doesn't matter what referer I have. I only want to re-direct visitors from yahoo, google and msn to the newpage.html all other visitors should continue to go to root.

Thanks in advance,
Andy

[edited by: jdMorgan at 3:04 am (utc) on May 30, 2007]
[edit reason] example.com [/edit]

g1smd

7:58 pm on May 29, 2007 (gmt 0)

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




The [OR] function may be better served using
RewriteCond %{HTTP_REFERER} (yahoo¦google¦msn)\..*$
or something similar.

One thing to point out is that you have a 302 redirect there as you only used [R] not [R=301].

jdMorgan

3:02 am on May 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code should have worked. Did you flush your browser cache completely between testing sessions?

As g1smd says, you can shorten that up considerably. You can also make it more robust at the same time:


RewriteBase /
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://([^.]+\.)*(yahooŚgoogleŚmsn)\.
RewriteRule ^$ http://www.example.com/newdirectory/newpage.html [R=302,L]

Solve the primary problem first, though.

Jim

[edited by: jdMorgan at 3:03 am (utc) on May 30, 2007]

g1smd

7:18 pm on May 30, 2007 (gmt 0)

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



Are you sure you want a 302 redirect, or should it be a 301?

marko008

11:14 pm on May 30, 2007 (gmt 0)

10+ Year Member



I need this type of redirecting done on my site as well, but I'm not comfortable doing it. Still a newbie at this whole thing and it's not worth screwing up our site over. Anyone capable and interested in doing something like this for us?

andy2005

12:27 am on Jun 2, 2007 (gmt 0)

10+ Year Member



Hi,

Thanks for all replies but for some odd reason it is not working.

When I use the code jdMorgan replied with (after changing it to right urls etc) the only difference is that before ALL traffic went to the new page. Now ALL traffic goes to the old page (/).

I did as suggested emptied all cache and cookies etc both in Firefox and IE but no difference.

Anyone that have an idea what it could be? :)

Thanks

Andy

jdMorgan

11:56 pm on Jun 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Either your installation of mod_rewrite is corrupted, the regex library in your OS is broken, or some change you are making between what is posted here and what you are actually using is breaking the code.

Please consider posting details, changing only the domain name and any possibly-objectionable or uniquely-identifiable words in the URLs.

The code I posted should redirect only the "/" home page if a robot requests it, due the the "^$" pattern I copied from your original rule.

Jim