homepage Welcome to WebmasterWorld Guest from 54.145.183.190
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / WebmasterWorld / Webmaster General
Forum Library, Charter, Moderators: phranque

Webmaster General Forum

    
htaccess - redirecting traffic
from a specific domain
Doood

10+ Year Member



 
Msg#: 3086 posted 2:40 pm on Aug 9, 2003 (gmt 0)

Some website is sending me lots of traffic, but to the wrong page. I can't get in touch with them and they don't know I need the url changed.

So what do I use in the htaccess to redirect traffic from a specific domain only, to a specific page on my site?

I'm already using a redirect for a changed page on my site like below. Do you think adding another one like that one would work by using their domain in the "redirect" part?

Redirect permanent /oldpage.htm [domain.com...]

 

le_gber

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3086 posted 11:17 am on Aug 11, 2003 (gmt 0)

Yes it should work
have a look here:
[webmasterworld.com...]

Doood

10+ Year Member



 
Msg#: 3086 posted 3:55 am on Aug 13, 2003 (gmt 0)

That won't work because I'm not redirecting traffic from an old page to a new page. I want to redirect all traffic coming from a specific domain to a different page than the url they are sending traffic to.

Some site is linking to my index.php page, but they should be using a different url (differenturl.php) and I can't get in contact with them to get it changed. I only want to redirect traffic coming from one specific domain.

Anyone know how thats done?

wkitty42

10+ Year Member



 
Msg#: 3086 posted 5:57 am on Aug 13, 2003 (gmt 0)

doood,

sure you are, aren't you? think about it for a sec... they are directing to a page that doesn't exist any more, right?

or does that page exist but you want to present something else?

in any case, if your server works "apache style", the following might work for you...

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^\/index\.php$
RewriteCond %{REFERER_STRING} other.domain$
RewriteRule /index.php /otherurl.php? [R=301,L]

if i've done this right, it says...

1. if the query string is /index.php AND 
2. if the referrer string is other.domain THEN
3. internally redirect with a 301 code from /index.php to /otherurl.php

hopefully jdMorgan is watching over my shoulder ;)

Doood

10+ Year Member



 
Msg#: 3086 posted 6:25 am on Aug 13, 2003 (gmt 0)

The index.php exists but I don't want traffic from a certain domain going to that page.

Ok, so in {REFERER_STRING} other.domain$ I put in the domain where the traffic is coming from and it should redirect it from index.php to otherurl.php? Is that correct. Sounds like it could work.

Someone was trying to tell me this might work
RewriteCond %{HTTP_USER_AGENT} ^NameOfBadRobot.*
RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.[8-9]$
RewriteRule ^/~quux/foo/arc/.+ - [F]

I don't know though, cause it's a robot block and I'm not dealing with robots.

wkitty42

10+ Year Member



 
Msg#: 3086 posted 6:59 am on Aug 13, 2003 (gmt 0)

doood,

yes, that's pretty much it... use the %{referer} part to identify where its coming from and the %{query_string} to determine what it is that's being asked for... both are rewritecond's and then followed by the rewriterule... please also verify the correct terms vis a vis %{referer} and %{query_string}... also note that CaPitaLiZation is important with regard to the commands... you can use [NC] after each of the rewritecond's to make then NoCase sensitive... that way INDEX.php will match index.php and such...

also remember, if you already have a .htaccess file, back it up first so that if something goes wonky on ya, you can put it back in place and start again...

Doood

10+ Year Member



 
Msg#: 3086 posted 3:59 pm on Aug 13, 2003 (gmt 0)

I tested it and from another site on my server and it didn't work, nothing at all happened. Below is what I tried, testdomain.com is where it was tested from. It looked like it should have worked.

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^\/index\.php$
RewriteCond %{REFERER_STRING} testdomain.com$
RewriteRule /index.php /otherurl.php? [R=301,L]

claus

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3086 posted 4:36 pm on Aug 13, 2003 (gmt 0)

I have modified it slightly below:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(\/\/index\.php)$
RewriteCond %{HTTP_REFERER} testdomain.com/
RewriteRule ^/(index.php)?$ /otherurl.php [R=301,L]

First Cond: matches both "www.domain.com/" and "www.domain.com/index.php", as an "index" file is not always visible in the query string - in that case it's just "/".

Second Cond: referrer string does not have to end with "com", it can be ie "https://subdir3.testdomain.com/folder5/file-xyz.htm"

Rule: both "/" and "/index.php" gets redirected.

Hope this helps. Remember to replace the broken pipe "" with one entered from the keyboard (first cond).

/claus

Doood

10+ Year Member



 
Msg#: 3086 posted 5:22 pm on Aug 13, 2003 (gmt 0)

I put it in like you said

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(\/¦\/index\.php)$
RewriteCond %{REFERER_STRING} testdomain.com/
RewriteRule ^/(index.php)?$ /otherurl.php [R=301,L]

Still nothing happened.
All I did was replace the "¦" and changed testdomain.com to the actual domain where the link to index.php is. I guess I'm doing it right.

claus

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3086 posted 6:46 pm on Aug 13, 2003 (gmt 0)

well... i'm getting a bit in doubt if you really need this line, it does not seem necessary at all:

RewriteCond %{QUERY_STRING} ^(\/\/index\.php)$

The RewriteRule includes exactly this anyway. And if you are sure that the annoying link has the "index.php" included, you should be able to write it like this:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} testdomain.com/
RewriteRule ^/index.php http://example.com/otherurl.php [R=301,L]

Note that i have replaced "/otherurl.php" with "http://example.com/otherurl.php" (the full URL). The problem is that a R=301 is an external redirect, that means that internal URL's cannot be used as replacement URLs. That is: "example.com" is your own domain name, use "www." in front of it if you normally do so.

I really hope this works now ;)

/claus

Doood

10+ Year Member



 
Msg#: 3086 posted 10:14 pm on Aug 13, 2003 (gmt 0)

The "annoying" link is just pointing to my domain and not directly to index.php

This is turning out to be more difficult than I thought.

Nothing seems to work, I've tried all different kinds of ways but still nothing.

Surely someone has done a right up on this somewhere.

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3086 posted 11:24 pm on Aug 13, 2003 (gmt 0)

Dood,

Yes, they've done a write-up in this thread itself. But help us as we try to help you, and be patient.

Since you are trying to make this work in an .htaccess context, you'll need to remove the leading slash from the pattern in the RewriteRule:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} testdomain\.com/
RewriteRule ^index\.php$ http://example.com/otherurl.php [R=301,L]

If the "problem link" on this other domain points to your domain only (and not to "index.php"), try:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} testdomain\.com/
RewriteRule ^$ http://example.com/otherurl.php [R=301,L]

Jim

Doood

10+ Year Member



 
Msg#: 3086 posted 2:01 am on Aug 14, 2003 (gmt 0)

Wow, it works!

I'm learning something new everday, so maybe one of these days I'll be back here giving back some of the stuff I've learned. I've been doing the "webmaster" thing for 2 years and I'm amazed at how much I don't know and how much more there is to learn.

Thanks to everyone that helped figure this out.

wkitty42

10+ Year Member



 
Msg#: 3086 posted 6:00 pm on Aug 14, 2003 (gmt 0)

Since you are trying to make this work in an .htaccess context, you'll need to remove the leading slash from the pattern in the RewriteRule:

arrrggghhh! i knew that i was missing something related to the differences between doing these in the .conf file and in the .htaccess... that one little thing, furrfu...

glad you dropped by this thread and got us straight, jdM ;)

Doood

10+ Year Member



 
Msg#: 3086 posted 2:25 pm on Aug 15, 2003 (gmt 0)

Since adding that redirect to the htaccess I've noticed this in the error logs

Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /home/virtual/site10/fst/var/www/html/_vti_bin/owssvr.dll

I've also noticed that not everyone that comes from the domain the traffic is being redirected from is getting redirected. That's ok though cause it's only 1 every 5 mins or so and I'm not really concerned about it.

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3086 posted 4:53 pm on Aug 15, 2003 (gmt 0)

Is your rewrite installed in one of these directories?

/home/virtual/site10/fst/var/www/html/_vti_bin/
/home/virtual/site10/fst/var/www/html/

If not, then maybe the request is not encountering the Option +FollowSymLinks directive in the code posted above.

If some requests are getting through, it is likely that we've missed a detail in the HTTP_REFERER or the requested URI. That is, the referer and requested file must match exactly as specified in the rules in order for the rewrite to work.

Jim

Doood

10+ Year Member



 
Msg#: 3086 posted 4:08 pm on Aug 16, 2003 (gmt 0)

the htaccess is in /home/virtual/site10/fst/var/www/html/

It's working for the most part, but only a few aren't being redirected

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / Webmaster General
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