Mass Virtual Hosting [htaccess]

In essence, redirect requests for a domain to a subfolder — this is one of the tactics for multisite installations.

In .htacces file:

RewriteEngine On
RewriteBase /
RewriteCond   %{REQUEST_FILENAME} !-f
RewriteCond   %{REQUEST_FILENAME} !-d
RewriteCond   %{HTTP_HOST}                 ^www\.[^.]+\.com$
RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
RewriteRule   ^www\.([^.]+)\.com(.*) /htdocs/projects/$1$2

Source: Stack Overflow Question – htaccess to redirect to a sub-directory based on the host name
Followup: Dynamic mass virtual hosts with mod_rewrite

Similarly, map from a subdomain to a subfolder:
i.e. map from to /home/SITE/www

RewriteEngine on
RewriteMap lowercase int:tolower
RewriteCond %{lowercase:%{HTTP_HOST}} ^www\.([^.]+)\.example\.com$
RewriteRule ^(.*) /home/%1/www$1

Leave a Reply

Your email address will not be published. Required fields are marked *