oshirowanen
oshirowanen

Reputation: 15965

Redirect second domain name?

I have the following .htaccess file which works fine for say www.companyone.com:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ /index.php?/$1 [L]

I also have the domain www.companytwo.com which points to the same site, i.e. www.companyone.com. The problem is that when someone uses www.companytwo.com which correctly goes to the original website, the url still contains www.companytwo.com, when it should become www.companyone.com.

So in effect, I am ending up with 2 duplicate sites which is bad for seo. Using the above .htaccess file, I am already ensuring that if a user types companyone.com, they automatically get redirected to www.companyone.com. I need the same thing for www.companytwo.com, i.e. companytwo.com and www.companytwo.com should become www.companyone.com.

Is this something I need to fix via the .htaccess file or some virtual server file?

Upvotes: 1

Views: 122

Answers (1)

blang
blang

Reputation: 2120

You can redirect the Browser to your www.companyone.com site by using .htacces:

# Redirect to www.companyone.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^companytwo.com$ [OR]
RewriteCond %{HTTP_HOST} ^companyone.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.companytwo.com$
RewriteRule (.*)$ http://www.companyone.com/$1 [R=301,L]

# If your example works, this rewrite to index.php/$1
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ /index.php?/$1 [L]

Upvotes: 2

Related Questions