Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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]
</IfModule>
share|improve this question
add comment

2 Answers

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/
 </IfModule>
share|improve this answer
1  
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
add comment

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
add comment

Your Answer

 
discard

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.