homepage Welcome to WebmasterWorld Guest from 54.205.254.108
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
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
netdude




msg:1518233
 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}
^http://whatever.com
RewriteRule /* [anotherdomain.com...]
[R,L]

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

 

jdMorgan




msg:1518234
 11:06 pm on Sep 19, 2003 (gmt 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

netdude




msg:1518235
 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.

netdude




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

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

jdMorgan




msg:1518237
 1:30 am on Sep 20, 2003 (gmt 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]

netdude




msg:1518238
 3:36 am on Sep 20, 2003 (gmt 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]

closed




msg:1518239
 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 "."

netdude




msg:1518240
 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

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]

closed




msg:1518241
 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