Welcome to WebmasterWorld Guest from 54.161.49.216

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

302 Redirect, but not for all incoming referrers

I don't want users coming from some domain to be referred.

     
6:19 pm on Oct 22, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 1, 2006
posts:45
votes: 0


Hello, today I made a 302 redirect in .htaccess to another domain.
The 302 to the page is actually an exact mirror of the source page.
For bandwidth reasons I don't want to refer everyone to the new page.
I know that from one domain I get a lot of traffic, I don't want users coming from that domain to go to my new page.

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.

4:11 pm on Oct 24, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 1, 2006
posts:45
votes: 0


Hello I didn't get a reply to this but really it should be possible to exclude some users to follow the 302 redirect right?
Users coming from 1 domain must not follow the 302 redirect.

I hope someone can help me with this one.

4:24 pm on Oct 24, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Please explain "not supporting apache":

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

10:08 pm on Oct 24, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 1, 2006
posts:45
votes: 0


Well I got it after doing some two hour research.
What I want is actually below and it seem to work, but is this optimized?

#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]

11:28 pm on Oct 24, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


I'd recommend a few tweaks:

RewriteCond %{HTTP_REFERER} !^http://(www\.)?allowed-domain\.com [NC]
RewriteCond %{HTTP_REFERER} .
RewriteRule ^(.*\.html)$ http://www.new-website.com/$1 [R=302,L]

Jim

[edited by: jdMorgan at 11:29 pm (utc) on Oct. 24, 2006]

9:13 am on Oct 25, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 1, 2006
posts:45
votes: 0


Hello JDmorgan,

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.

5:10 pm on Oct 25, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 1, 2006
posts:45
votes: 0


I tried a lot of things with HTTP_HOST , I want direct type-in traffic and allowed-domain.com not to follow the 302 redirect.

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]

4:49 am on Oct 26, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Again, the following should be entirely equivalent:

# 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]

(A pattern which is not back-referenced and which starts with "^.*" or ends with ".*$" is almost always an utter waste of CPU time, and can be omitted. In this case, it allows you to remove an RewriteCond entire line.)

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]

Jim
8:00 am on Oct 26, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 1, 2006
posts:45
votes: 0


Hey JdMorgan, I tried your code but it still refers all type-in traffic.
(My .htaccess is placed in the subdomain root of the domain, which is under my control, the full domain is not under my control)
I could use your better writing techniques though, so I could skip some rules out of it.

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]