Welcome to WebmasterWorld Guest from 54.159.242.217

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Referrer redirection with .htaccess

Referrer redirection with .htaccess

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

New User

10+ Year Member

joined:Sept 19, 2003
posts:7
votes: 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}
^http://whatever.com
RewriteRule /* [anotherdomain.com...]
[R,L]

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

11:06 pm on Sept 19, 2003 (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


netdude,

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.

Jim

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

New User

10+ Year Member

joined:Sept 19, 2003
posts:7
votes: 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 Sept 19, 2003 (gmt 0)

New User

10+ Year Member

joined:Sept 19, 2003
posts:7
votes: 0


I looked at that link you provided, i'm totally lost now.
1:30 am on Sept 20, 2003 (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


netdude,

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.

Jim

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

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

New User

10+ Year Member

joined:Sept 19, 2003
posts:7
votes: 0


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

[subdomain.mydomain.com...]

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

Thanks

[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 Sept 20, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Aug 20, 2003
posts:255
votes: 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 Sept 20, 2003 (gmt 0)

New User

10+ Year Member

joined:Sept 19, 2003
posts:7
votes: 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

subdomain1.mydomain.com

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 Sept 20, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Aug 20, 2003
posts:255
votes: 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.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members