Reputation: 14934
I've a hosting setup, where my primary domain is domain1.com. A list a other domain is added as aliases, say domain2.com and domain3.com. When visiting for instance domain2.com, the URL in the browser is still domain2.com, but I would like it to me my primary domain.
Therefore I would like to redirect requests to all other domains except from domain1.com to domain1.com. How can I do this using RewriteEngine?
I'm trying this one:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www.)?domain1.com$ [NC]
RewriteRule .* http://www.domain1.com/$1 [L,NC]
It works fine, except that I would like domain2.com/folder to redirect to domain1.com/folder.
Upvotes: 1
Views: 512
Reputation: 42915
Ok, if your setup works except that issue with the path of the url being ignored during the rewrite process, then I suggest you add the brackets as required in the rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www.)?domain1.com$ [NC]
RewriteRule (.*) http://www.domain1.com/$1 [L,NC]
A good practice if you want to debug rewriting stuff is to use logging. That way you can understand exactly what is actually happening inside the rewriting engine, step by step. You need the two commands RewriteLog
and RewriteLogLevel
, again this is explained in the documentation in depth.
Upvotes: 2