Skip to content

Instantly share code, notes, and snippets.

@buschtoens
Created May 6, 2013 00:13
Show Gist options
  • Save buschtoens/5522686 to your computer and use it in GitHub Desktop.
Save buschtoens/5522686 to your computer and use it in GitHub Desktop.
Dynamic VHost with mod_rewrite
# Mod Rewrite
RewriteEngine on
RewriteBase /
# Top Level Domains
RewriteCond %{HTTP_HOST} ^(?:.*?)([^.]+\.[^.]+)(?::80)?$ [NC]
RewriteCond %{REQUEST_URI} !^/domains
RewriteCond %{DOCUMENT_ROOT}/domains/%1 -d
RewriteRule ^(.*) /domains/%1/$1 [L]
# Subdomains
RewriteCond %{HTTP_HOST} ^(?:.*?)([^.]+)\.([^.]+\.[^.]+)(?::80)?$ [NC]
RewriteCond %{REQUEST_URI} !^/subdomains
RewriteCond %{DOCUMENT_ROOT}/subdomains/%2/%1 -d
RewriteRule ^(.*) /subdomains/%2/%1/$1 [L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment