I have 2 TLDs example.com
and example.ie
.
example.com
and example.ie
both point at the same IP address and pull the same content now we could get whacked with a ban hammer from Google for duplicate content so we want anyone accessing *.example.ie
and *.example.com
to be redirected to www.example.com
the problem is as they are both pointing at the same server the .htaccess is the same thus I don't believe we can do the usual:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
So how do we go about creating a search-engine friendly 301 redirect from *.example.ie
and *.example.com
to www.example.com
?
I would do it like this:
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [R=301,L]
That will redirect (statuscode 301 "permantly moved") every domain which is not www.example.com to www.example.com.
The 301 redirect you posted is just fine; the HTTP header of every request (nowadays) contains the name of the host.
As an alternative, you can use rel=canonical
. It's not that urgent anyway, as duplicate content on just two domains is unlikely to be a problem.
来源:https://stackoverflow.com/questions/7847814/301-redirect-where-2-domains-point-to-same-ip