Forum Moderators: phranque
suburbia.example.com goes (invisibly) to http://www.example.com/potn/sw/?username=suburbia
I had it working OK with less code, although the www 'subdomain' was being included as well. When I tried to implement the exclusion, nothing seemed to work. Any and all help very much appreciated WebmasterWorld!
Here is the htaccess code I am currently using:
Options -Indexes
ErrorDocument 404 /errors/index.php?404
ErrorDocument 403 /errors/index.php?403
RewriteEngine On
# If no-www domain requested, externally redirect to www domain
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
# If www+subdomain domain requested, externally redirect to subdomain without "www"
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com
RewriteRule (.*) http://%1.example.com/$1 [R=301,L]
#
# If subdomain+www domain requested, externally redirect to subdomain without "www"
RewriteCond %{HTTP_HOST} ^([^.]+)\.www\.example\.com
RewriteRule (.*) http://%1.example.com/$1 [R=301,L]
#
# If subdomain requested, rewrite subdomain and html page requests to index.php with query string
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^$ /potn/sw/?username=%1 [L]
#
# If subdomain requested, rewrite home page requests to index.php with query string user=subdomain & page="home"
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^$ /potn/sw/?username=%1 [L]
[edited by: jdMorgan at 6:08 pm (utc) on Feb. 21, 2007]
[edit reason] Example.com [/edit]
# If no-www domain requested, externally redirect to www domain
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
# <Combined two rules to create this one>
# If www+subdomain or subdomain+www domain requested, externally redirect to subdomain without "www"
RewriteCond %{HTTP_HOST} ^([^.]+)\.www\.example\.com [OR]
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com
RewriteRule (.*) http://%1.example.com/$1 [R=301,L]
#
# <Reversed next two rules to put the most specific rule first>
# If subdomain requested, rewrite home page ("/" or "/index.html" only) requests to index.php with query string user=subdomain&page=home
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^(index\.html)?$ /potn/sw/?username=%1&page=home [L]
#
# If subdomain requested, rewrite subdomain and html page requests to index.php with query string user=subdomain&page=<requested_pagename>
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^(.+)\.html$ /potn/sw/?username=%1&page=$1 [L]