Forum Moderators: phranque
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]
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]
Jim
[edited by: jdMorgan at 3:03 am (utc) on May 30, 2007]
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
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