Exclude sub domain rewrite non www to www in htacces

I’m having a Magento multistore setup and i’m sending all non www requests to www in the .htacces with the rewrite:

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

I’m using a sub domain for testing new websites and for this sub domain I don’t need this rewrite. Therefore I use:

RewriteCond %{HTTP_HOST} ^sub.domain.com [NC]
RewriteRule ^(.*) - [L]

Only problem now is that when I go to http:// sub.domain.com it works, but when I go to a category or product for example http:// sub.domain.com/cat1 or http:// sub.domain.com/product-red.html it doesn’t work any more and I get a “Not Found” message.

What do I need to add to the code so it excludes the whole sub domain, including everything after the / ?


Source: .htaccess

Leave a Reply