Forum Moderators: phranque
A company I work for has registered about 10 domain names.
The site I want to be known as is www.domain.com, and this is the site that I update.
If you type in XXXX-domain.com it shows the exact content of the page, same happens if you do YYYY-domain.com, ZZZZ-domain.com, AAAA-domain.com.
It is not a simple redirect, it shows the exact contents of the site: XXXX-domain.com/page1.html is the same as domain.com/page1.html same for page2.html folder/page6.html
The "duplicate" domains will only work if you do not type in www. before them. I am not sure what this means.
Can someone please help me with writing an .htaccess file or script that will prevent the "duplicate" domains from copying the entire content and just redirect to the real domain?
I have read this: [webmasterworld.com...] and am still clueless, as well as a dozen or so others.
so far I have tried the following:
redirect / http ://www.domain.com
this made it so if I typed http ://www.domain.com/index.html it would look for http ://www.domain.comindex.html
redirect / http ://www.domain.com/
this puts it in a loop where nothing works, and just keeps refreshing.
redirect http ://XXXX-domain.com [domain.com...]
this did nothing
Please help, I am going crazy.
Thank you
You'll need to use mod_rewrite to do a conditional redirect:
In your web-root .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{HTTP_HOST} !^192\.168\.0\.1 <--Put your server's unique IP address here
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
Be sure to escape the periods in the regex patterns as shown, by preceding them with a backslash.
Also make sure the domain name parts in the first and third lines are the same, except for those backslashes.
Including the IP address allows you to access the site in case of DNS failure. Omit this entire line if your IP address is shared with other company's web sites.
HTH,
Jim
If it is hard I will just forget it and just be happy with what I have already recieved.
Thanks again.
> there are some incoming links that go to www.XXXX-domain.com and that shows nothing...
Can you clarify that? If your DNS records point those URLs to your server, the code I posted above should redirect them, too - Translated to plain english, it says,
IF the requested HOST is NOT www.domain.com
AND the requested HOST is NOT our IP address,
THEN do a 301 redirect to [domain.com...]
Thus, it should redirect any subdomain requests that arrive at your server and cause your .htaccess file to be processed.
Jim