Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess: exluce some domain in RewriteCond

this is my .htaccess code so if the user type just domain.com will be redirected to www.domain.com

RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

my problem now is that i have a new domain pointing to the same domain path so even the new domain is redirected "transparently" to domain.com...

how can i exclude some domain name from that rule?

thanks!

like image 876
Francesco Avatar asked Apr 13 '11 14:04

Francesco


1 Answers

You could try making the rewrite generic, so all requests that are not starting with www are redirected, but on the correct/requested domain.

RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [L,R=301]

Or, you can check instead for if the domain starts with domain.com:

RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com [L,R=301]

Hopefully this helps.

like image 81
clmarquart Avatar answered Sep 27 '22 21:09

clmarquart