the solution depends on how your hosting provider implements multi-subdomain mapping. Some offer a control panel so that you can register your subdomains and point each to a separate subdirectory in your file space. Some will just map *.yourdomain.zzz
to the document root for yourdomain.zzz
, and from your description, this is what is happening for you. In this case you need to decode the HTTP_HOST variable and route on that. But you also need to stop your rewrite rule looping so that sub1.yourdomain.zzz
doesn’t get mapped to yourDocRoot/sub1/sub1/sub1…`
If you wanted to process sub1 and sub2 subdomains, then you would do this with a rule in you top level like this:
RewriteBase /
RewriteCond %{ENV:REDIRECT_INSUB} !=1
RewriteCond %{HTTP_HOST} (sub1|sub2)\.yourdomain\.zzz
ReweriteRule ^(.*) %1/$1 [L,E=INSUB:1]
Search for [.htaccess] HTTP_HOST to see lots of variants of this.
1
solved Redirect folder to subdomain