2

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?

Myles Gray
  • 8,711
  • 7
  • 48
  • 70

2 Answers2

5

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.

Seybsen
  • 14,989
  • 4
  • 40
  • 73
  • This looks fine to me, have an upvote! :) Maybe you should add the QSA flag, though. – middus Oct 21 '11 at 11:02
  • No need for QSA here. It gets already appended. So if you open example.com/index.php?site=123 you will get redirected to www.example.com/index.php?site=123 .. or am I missing sth? – Seybsen Oct 21 '11 at 11:12
  • 1
    I'll mark this as the answer what I used in the end was: `RewriteEngine On RewriteCond %{HTTP_HOST} !^www.example.com [nocase] RewriteRule (.*) http://www.example.com/$1 [last,redirect=301]` – Myles Gray Oct 21 '11 at 11:17
  • 1
    @Myles Gray: you should escape dots in regexp like \. in your RewriteCond – Seybsen Oct 26 '11 at 17:41
0

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.

middus
  • 9,103
  • 1
  • 31
  • 33
phihag
  • 278,196
  • 72
  • 453
  • 469