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>
link|improve this question

feedback

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>
link|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
feedback

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 /

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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