Forum Moderators: phranque
How can I prefend users to be referred in this case? I need to disable the 302 redirect for users of that referrer domain only.
I want to do this in .htaccess but it's not supporting apache, so it should be "basic text for it" I guess. thank you.
I want to do this in .htaccess but it's not supporting apache, so it should be "basic text for it" I guess.
The solution is to use RewriteCond to test the referrer variable %{HTTP_REFERER}, and then use a RewriteRule to do the redirect only if the result of that test indicates that the referrer is NOT a particular site.
This is very similar to common anti-hotlinking code, where visitors referred from hotlinking pages are redirected to an alternate image.
See the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
#Starting mod_rewrite...
RewriteEngine on
#The referer URL's that are allowed to link files.
#The third (no referer) represents a link typed in.
RewriteCond %{HTTP_REFERER}!^http://(www\.)?allowed-domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?allowed-domain.com.*$ [NC]
RewriteCond %{HTTP_REFERER}!^$
#The file that will returned to all but the above allowed referers.
RewriteRule \.(html)$ [new-website.com...] [R=302,L]
your simplified script does follow the 302 redirect for urls like [allowed-domain.com...] those are redirected to www.new-website.com but they shouldn't.
I actually want all referrers from allowed-domain.com including subdomains not to follow the 302 redirect, with your script this does not work?
I can use my own script (it works) but I have another issue with that, if there is no referrer it doesn't follow the 302 redirect.
I want direct typein traffic to be allowed = no referrer, but I do want to make Google follow the redirect, the problem is the googlebot doesn't have a referrer aswell.
However the direct type-in traffic DOES follow the 302 redirect.
I know I could use!^$ to allow non-referer traffic, but then the search engine bots won't follow the 302.
I just can't get it to work, I must allow searchengine bots to follow the 302, but at the same time I have to disable the 302redirect for direct type-in traffic. (both are non-referer traffic!)
Hope I could get this to work finally?
#Starting mod_rewrite...
RewriteEngine on
#The referer URL's that are allowed to link files.
#The third (no referer) represents a link typed in.
RewriteCond %{HTTP_HOST}!^sub\.website\.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?allowed-domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?allowed-domain.com.*$ [NC]
#The file that will returned to all but the above allowed referers.
RewriteRule \.(html)$ [new-website.com...] [R=302,L]
# Starting mod_rewrite...
RewriteEngine on
#
# The referer URL's that are allowed to link files.
RewriteCond %{HTTP_HOST} !^sub\.website\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?allowed-domain\.com [NC]
# The file that will returned to all but the above allowed referers.
RewriteRule \.html$ http://www.new-website.com/ [R=302,L]
Note that your original code (and the code above) will redirect any request for any page to the 'home page' of new-website.com -- no requested-page information is being passed-through.
If you wish to preserve the requested URL-path, then change the rule:
RewriteRule ^(.+\.html)$ http://www.new-website.com/$1 [R=302,L]
Anyway this code below seems to do what I want, allowed-site.com and direct type-in traffic is not refered but the searchengine bots are following the 302 like I want.
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^http://(www\.)?allowed-site\.com [NC]
RewriteCond %{HTTP_REFERER}!^$
RewriteRule \.html$ [new-website.com...] [R=302]
RewriteCond %{HTTP_USER_AGENT} googlebot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Slurp [NC,OR]
RewriteCond %{HTTP_USER_AGENT} msnbot
RewriteRule \.html$ [new-website.com...] [R=302,L]