Forum Moderators: phranque

Message Too Old, No Replies

redirect external referrer (htaccess)

redirect external referrer

         

tuuni

11:24 pm on Feb 6, 2010 (gmt 0)

10+ Year Member



How to redirect all traffic (to my site's certain htm page.. example: sub.site.com/folder/file.htm) who are not coming directly to my site.

Something like this but this is not correct..

RewriteCond %{HTTP_REFERER} !^http://sub.example.com
RewriteRule !^$ http://sub.example.com/folder/file.htm [R=302,L]

How can it be done?

[edited by: jdMorgan at 10:05 pm (utc) on Feb 7, 2010]
[edit reason] example.com [/edit]

tuuni

7:44 pm on Feb 7, 2010 (gmt 0)

10+ Year Member



anyone?

jdMorgan

10:18 pm on Feb 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You did not say how you tested, what results you got, and how those results differed from what you expected, so we can only guess why you think your code is incorrect. I'd suggest:

RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://sub\.example\.com
RewriteRule ^(([^.]+\.)+(s?html?|php[0-9]{0,2}))?$ http://sub.example.com/folder/file.htm [R=302,L]

"IF the referer is sub.example.com, sub.example.com., sub.example.com:80, sub.example.com,:80, or blank (these are all perfectly-valid HTTP Referrer values),
AND if the request is for a .shtml, .shtm, .html, .htm, .php, or .php5 'page' or a blank URL-path indicating your 'home page',
THEN redirect to sub.example.com/folder/file.htm"

Jim