Mod_rewrite to dynamically map subdomain directories.


/ Published in: Apache
Save to your folder(s)

Add to vhost block. Dynamically maps all subdomains of sub.example.com to their respective document root. Note: Doesn't work great when the sub sub needs to add additional mod_rewrite rules of its own, i.e., a Drupal installation.


Copy this code and paste it in your HTML
  1. ServerAlias *.sub.example.com
  2.  
  3. RewriteEngine on
  4. RewriteCond %{HTTP_HOST} ^(www\.)?(.+)\.sub\.example\.net
  5. RewriteCond /Users/username/Sites/sub/%2/httpdocs -d
  6. RewriteRule ^(.*) /%2/httpdocs/$1 [L]

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.