homepage Welcome to WebmasterWorld Guest from
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

Referrer redirection with .htaccess
Referrer redirection with .htaccess

 10:53 pm on Sep 19, 2003 (gmt 0)

I'm new to .htaccess.

How would I redirect a referrer to another website?

This is the code I've tried that does not work.

RewriteEngine On
RewriteCond %{HTTP_REFERER}
RewriteRule /* [anotherdomain.com...]

[edited by: DaveAtIFG at 4:26 pm (utc) on Sep. 20, 2003]



 11:06 pm on Sep 19, 2003 (gmt 0)


Welcome to WebmasterWorld [webmasterworld.com]!

What referer are you trying to redirect?

You should probably take a look at this Introduction to mod_rewrite [webmasterworld.com] thread and the documentation and tutorials it cites to get you started.



 11:27 pm on Sep 19, 2003 (gmt 0)

A person I know who i'm not crazy about has a link to my site on his. I want it so when somebody clicks on the link to my site off his to get redirected to whatever site I choose.

Do you have a code for this? Thanks.


 11:34 pm on Sep 19, 2003 (gmt 0)

I looked at that link you provided, i'm totally lost now.


 1:30 am on Sep 20, 2003 (gmt 0)


I'll assume that the referer is "whatever.com" and not an IP address, then.

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://whatever\.com
RewriteRule .* http://www.anotherdomain.com [R=301,L]

If the problem is that the code "does nothing at all", then you may need to add

Options +FollowSymLinks

at the top of the code above.

The Rewriting Guide cited in the thread I gave you contains this and many other useful examples.


[edited by: DaveAtIFG at 4:26 pm (utc) on Sep. 20, 2003]


 3:36 am on Sep 20, 2003 (gmt 0)

Thanks. One more question. The domain i'm trying to block is


so how would I type that out with the foward and back slashes?


[edited by: netdude at 4:31 am (utc) on Sep. 20, 2003]

[edited by: DaveAtIFG at 4:42 am (utc) on Sep. 20, 2003]


 4:08 am on Sep 20, 2003 (gmt 0)

Uh, dude, I'd advise editing the URL you just posted so that it's more generic. Maybe use something like http://subdomain.mydomain.com/somedirectory.

Assuming that's the address that you're trying to block, you'd replace this line:

RewriteCond %{HTTP_REFERER} ^http://whatever\.com

to this:

RewriteCond %{HTTP_REFERER} ^http://subdomain\.mydomain\.com/somedirectory

So it's just the address, but you put a backslash before each "." so that instead of matching any character in that spot, you literally match "."


 4:28 am on Sep 20, 2003 (gmt 0)

Thanks bro, that did the trick.

That wasn't really the real URL I was trying to block, hehe.
But it is a hometown address.

One more question, if I wanted to block


and subdomain2.mydomain.com

would it look like this?

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://subdomain1\.mydomain\.com/[OR]
RewriteCond %{HTTP_REFERER} ^http://subdomain2\.mydomain\.com/
RewriteRule .* [anotherdomain.com...] [R=301,L]

thanks again for all your help.

[edited by: DaveAtIFG at 4:31 pm (utc) on Sep. 20, 2003]


 4:50 am on Sep 20, 2003 (gmt 0)

Just making sure, dude.

Now, about your question: Yup. Or you could just use one RewriteCond, instead of using two, this way:

RewriteCond %{HTTP_REFERER} ^http://(subdomain1¦subdomain2)\.mydomain\.com/

But you'd have to replace the ¦ here with the one on your keyboard to get it to work correctly.

You're welcome for my part.

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