Forum Moderators: phranque
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...]
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?
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 ;)
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.
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...
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^\/index\.php$
RewriteCond %{REFERER_STRING} testdomain.com$
RewriteRule /index.php /otherurl.php? [R=301,L]
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
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.
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
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]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} testdomain\.com/
RewriteRule ^$ http://example.com/otherurl.php [R=301,L]
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.
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:
glad you dropped by this thread and got us straight, jdM ;)
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.
/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