Forum Moderators: phranque
Say there are two domain names, www.name1.com and www.name2.com, both pointing to the same IP. How can I redirect specific pages from one domain name to the other, without causing infinite loops?
For example,
www.name2.com/hello.html gets magically changed to www.name1.com/hello.html
any other page reference to name2.com gets left alone.
Thanks for any help, much appreciated.
Welcome to WebmasterWorld [webmasterworld.com]!
If you use mod_rewrite [httpd.apache.org] to do the redirects, you can examine the user-requested domain name using the HTTP_HOST variable to avoid the loop:
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com
RewriteRule ^hello\.html$ http://www.domain1.com/hello.html [R=301,L]
Jim
Since adding this, I've noticed that my hotlink protection is no longer working. I don't suppose these new rules would be interfering somehow?
The hotlink part, which should be allowing 2 domain names access but denying all others, is here:
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?name1\.com [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?name2\.com [NC]
RewriteRule [^/]+.(gif¦jpg¦png¦pdf¦swf¦zip¦exe¦mpg¦avi¦mpeg¦mp3)$ - [F]
Thanks.
Your code allows access to requests with blank referrers, which it should. This is to prevent major problems with your visitors who are behind proxy caches or those using "internet security" software (both of which can suppress the referrer without the user knowing about it) to access your images. This *is* a hole in the image "security" scheme, but if you want to use simple referrer blocking, you basically have to leave the hole open, otherwise you are going to need a full-time "help desk" for your legitimate visitors. If you need more protection use cookies or sessions.
Jim