Skip to content

Instantly share code, notes, and snippets.

@bmsterling
Created April 17, 2011 02:46
Show Gist options
  • Save bmsterling/923704 to your computer and use it in GitHub Desktop.
Save bmsterling/923704 to your computer and use it in GitHub Desktop.
Allows you to create subdomains on the fly w/out you having to create them in your cpanel
RewriteEngine On
RewriteBase /
# redirects subX.subY.domain.com to /-client/subY/subX
RewriteCond %{REQUEST_URI} !^/-
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.([^\.]+)
RewriteCond %{DOCUMENT_ROOT}/-clients/%3/%2 -d
RewriteRule ^(.*)$ -clients/%3/%2/$1 [L]
# redirects subY.domain.com to /-client/subY/
RewriteCond %{REQUEST_URI} !^/-
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)
RewriteCond %{DOCUMENT_ROOT}/-clients/%2 -d
RewriteRule ^(.*)$ -clients/%2/$1 [L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment