homepage Welcome to WebmasterWorld Guest from 54.167.138.53
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
htaccess again
How to redirect base on referer strings
Yidaki




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

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




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

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]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved