Reputation: 5779
Is it possible to configure .htaccess
so any subdomain will be redirected to it's corresponding folder without need to edit .htaccess
file every time I want to add the subdomain? How?
foo.domain.com -> /subdomains/foo
bar.domain.com -> /subdomains/bar
anything.domain.com/file.txt -> /subdomains/anything/file.txt
Thanks!
Upvotes: 1
Views: 44
Reputation: 784898
You can use this rule in site root .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^((?!www).+)\.domain\.com$ [NC]
RewriteRule ^((?!subdomains/).*)$ subdomains/%1/$1 [L,NC]
Upvotes: 1