Justin Lok
Justin Lok

Reputation: 1270

htaccess rewrite - redirect subdomain to directory for any domain

I need some help coming up with the correct .htaccess rule. Is there any sort of variable that allows 'brand1' to be anything and work correctly? If not, I would have to have a separate rewrite rule for brand1, brand2, brand3, brand4, etc. Same for the domain. Is there a variable that will allow this rule to work with any domain entered into the browser? I'd prefer to have one rewrite rule that can handle any brand and any domain together if possible, rather than a separate rule specifying each brand and each domain. This is for a Magento multistore setup.

RewriteCond %{HTTP_HOST} ^brand1\.domain\.com$
RewriteRule (.*) http://www.domain.com/brand1/$1 [P]

Any help you can provide would be much appreciated! Thanks!

Upvotes: 2

Views: 136

Answers (1)

anubhava
anubhava

Reputation: 786081

You can use:

RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$
RewriteRule (.*) http://www.domain.com/%1/$1 [L,P]

Upvotes: 1

Related Questions