Forum Moderators: phranque

Message Too Old, No Replies

Redirects with 2 domain names at same IP

         

Toca

2:24 pm on Apr 30, 2004 (gmt 0)

10+ Year Member



Hi,

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.

jdMorgan

2:51 pm on Apr 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Toca,

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]

Therefore, the redirect is based on the user-supplied domain name, and the common IP address doesn't matter.

Jim

Toca

4:35 pm on Apr 30, 2004 (gmt 0)

10+ Year Member



That works, thank you!

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.

jdMorgan

6:05 pm on Apr 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> hotlink protection is no longer working.

This is unclear. Does your code no longer stop hotlinking, or does it stop all image display?

Make sure you've flushed ALL caches between you and the server... Browser cache, proxy cache, etc.
You need to do this whenever you test mod_rewrite changes.

Jim

Toca

6:26 pm on Apr 30, 2004 (gmt 0)

10+ Year Member



Sorry for being unclear. I meant that other sites are able to link to the files without being stopped.

This only seems to be happening on Internet Explorer, despite clearing the cache. Mozilla seems to show the protection working, which is strange.

Thanks.

jdMorgan

8:14 pm on Apr 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's nothing in your code which distinguishes between Mozilla and IE. So the only question I can ask that makes any sense is, "Are the referring URLs showing in your log for the IE accesses?

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

Toca

8:57 am on May 2, 2004 (gmt 0)

10+ Year Member



Thanks for the help.

Internet Explorer is mysteriously passing a blank referer to my test page, which lets it get past the protection.. whereas Mozilla has the correct referer.