Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an existing Wordpress site setup at mycompany.tld1 and recently registered mycompany.tld2.

I want to setup a 301 redirect from mycompany.tld2 to mycompany.tld1, what would that .htaccess file look like? Can I append it to the Wordpress .htaccess file using a conditional statement to check the inbound URL?

WP .htaccess (existing):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
share|improve this question
up vote 2 down vote accepted

.htaccess would look a bit like this if you wanted to do a 301 redirect from mycompany.tld2 to mycompany.tld1.

<IfModule mod_alias.c>
      RedirectPermanent / http://mycompany/tld1/
share|improve this answer
RedirectPermanent is in mod_alias, not not_rewrite. – AlexD Jun 20 '11 at 10:41
Thank you that worked perfectly. – Trent Scott Jun 23 '11 at 3:41

Redirect all domains that are not your primary:

RewriteCond %{HTTP_HOST} !^www\.example\.tld1 [NC]
RewriteRule ^(.*)$ http://www.example.tld1/$1 [R=301,L]

Redirect only the secondary TLD to the primary:

RewriteCond %{HTTP_HOST} ^www\.example\.tld2 [NC]
RewriteRule ^(.*)$ http://www.example.tld1/$1 [R=301,L]

In your .htaccess file, I would suggest placing these right below RewriteBase /

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.