Welcome to WebmasterWorld Guest from 54.226.27.104

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess again

How to redirect base on referer strings

     

Yidaki

7:27 pm on Mar 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Folks, after searching like mad, i'm in the middle of nowhere with some special htaccess settings. I want to redirect unwanted visitors based on referer.

This is what we are trying to do:

If the HTTP_Referer of a request contains a string "badstring.com" we want to redirect the request to a page "go-fishing.htm". Our set up works - but the request returns a error page that (correctly) says "Document has moved here: http://example.com/go-fishing.htm". But we can't redirect them directly - without returning the error page.

Another problem with our code is: we have to specify a url but we want to specify a partial string (without http or tld).

Code we currently use:

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http(s)?://([a-z0-9-]+\.)*badstring.com/.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http(s)?://([a-z0-9-]+\.)*badstring.com/.*$ [NC]
RewriteRule /* http://%{HTTP_HOST}/go-fishing.htm [R,L]

Could someone please give me a code that works like i described above (forcing direct redirection)? BTW: the site runs on pure apache.

[edited by: jdMorgan at 3:01 pm (utc) on Oct. 25, 2003]
[edit reason] Examplified URLs per author's request [/edit]

Yidaki

5:09 pm on Mar 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, it goes like this:

RewriteEngine on
RewriteCond %{HTTP_REFERER} .*badstring.*
RewriteRule .* http://example.com/go-fishing.html [L]

Thanks for all the masses of answers and contributions to this great thread.

:)

[edited by: jdMorgan at 3:01 pm (utc) on Oct. 25, 2003]
[edit reason] Examplified URL per author's request [/edit]

 

Featured Threads

Hot Threads This Week

Hot Threads This Month