Forum Moderators: phranque
I have some problem, and could not find an answer online. I always used an .htaccess for redirecting, but it is not working properly with my new hoster. So, I have a problem.
I have various domains, pointing in one hosting account all on the same website. Now I want to use only one of the domains to be the official domain, with www. Si I did this in my .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.maindomain.com$ [NC]
RewriteRule ^(.*) [maindomain.com...] [L,R=301]
So far, so good. It`s working. But now I want all the other domains also to redirect into this maindomain. Means: The user enters one of my domain names and gets redirected (301) to the www.- version of my maindomain.com
Does anybody know what I have to do, to make it work?!
Let me know, thanks! Your help is very much apprechiated.
Jab
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^maindomain\.com
RewriteRule (.*) http://maindomain.com/$1 [R=301,L]
Jim
As long as the hostnames in both lines are the same, it will work as expected. Since the hostname in the RewriteCond is a regular-expressions pattern, the periods need to be escaped as shown, but otherwise, the hostnames in the two lines are identical.
So add the required "www" to both parts of the rule:
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.maindomain\.com
RewriteRule (.*) http://www.maindomain.com/$1 [R=301,L]
Jim