Skip to content

Instantly share code, notes, and snippets.

@designermonkey
Created April 7, 2012 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save designermonkey/2330774 to your computer and use it in GitHub Desktop.
Save designermonkey/2330774 to your computer and use it in GitHub Desktop.
Wildcard Subdomains
# Define specified subdomains first
<VirtualHost *:80>
ServerName subdomain.domain.com
DocumentRoot "/path/to/domain.com/subdomains/subdomain"
</VirtualHost>
# Define domain and wildcard subdomains second
<VirtualHost *:80>
ServerName domain.com
DocumentRoot "/path/to/domain.com/httpdocs"
ServerAlias domain.com www.domain.com *.domain.com
</VirtualHost>
# Rewrite Rule for wildcard subdomains
RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
RewriteRule (.*) %2/$1 [L]
### Symphony 2.3.x ###
Options +FollowSymlinks -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
### SECURITY - Protect crucial files
RewriteRule ^manifest/(.*)$ - [F]
RewriteRule ^workspace/utilities/(.*).xsl$ - [F]
RewriteRule ^workspace/pages/(.*).xsl$ - [F]
RewriteRule ^(.*).sql$ - [F]
RewriteRule (^|/)\. - [F]
### DO NOT APPLY RULES WHEN REQUESTING "favicon.ico"
RewriteCond %{REQUEST_FILENAME} favicon.ico [NC]
RewriteRule .* - [S=14]
### IMAGE RULES
RewriteRule ^image\/(.+\.(jpg|gif|jpeg|png|bmp))$ extensions/jit_image_manipulation/lib/image.php?param=$1 [L,NC]
### CHECK FOR TRAILING SLASH - Will ignore files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]
### URL Correction
RewriteRule ^(symphony/)?index.php(/.*/?) $1$2 [NC]
### ADMIN REWRITE
RewriteRule ^symphony\/?$ index.php?mode=administration&%{QUERY_STRING} [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^symphony(\/(.*\/?))?$ index.php?symphony-page=$1&mode=administration&%{QUERY_STRING} [NC,L]
### FRONTEND SUBDOMAIN REWRITE - Will ignore files and folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^([^.]+)\.([^.]+)\. [NC]
RewriteRule ^(.*\/?)$ index.php?symphony-page=subdomains/%1/$1&%{QUERY_STRING} [L]
### FRONTEND REWRITE - Will ignore files and folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*\/?)$ index.php?symphony-page=$1&%{QUERY_STRING} [L]
</IfModule>
######
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment