Forward a subdomain to a subfolder and preserve subfolder's .htaccess mod_rewrite rules Forward a subdomain to a subfolder and preserve subfolder's .htaccess mod_rewrite rules apache apache

Forward a subdomain to a subfolder and preserve subfolder's .htaccess mod_rewrite rules


I got it to work using VirtualHosts:

NameVirtualHost *# Root domain homepage<VirtualHost *>    DocumentRoot /var/www/domain.com/html    ServerName domain.com    ServerAlias www.domain.com</VirtualHost># Hosted sites<VirtualHost *>    VirtualDocumentRoot /var/www/vhosts/%0/html    ServerName *    ServerAlias *</VirtualHost>

The first entry catches requests to my home page and serves up the standard site, while the second catches EVERYTHING else and routes to a different location based on the host name requested.


Easy. Just make sure the subdomain is registered with your server's DNS, then point it with an htaccess like this:

RewriteEngine onRewriteCond %{HTTP_HOST} ^sub.domain.com$ [OR] RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.comRewriteRule .* /subfolder [L]

No need to mess with the subfolder's htaccess.