Forum Moderators: phranque
# Internally rewrite all index-page requests for all non-www subdomains to the
# sub_index.php script, passing the requested subdomain as "user=" parameter
# prevent recursion
RewriteCond %{QUERY_STRING} !^([^&]*&)*user=[^&]+
RewriteCond %{HTTP_HOST} !^www\.example.com
RewriteCond %{HTTP_HOST} ([a-zA-Z0-9]+)\.example.com
RewriteRule ^$ /sub_index.php?user=%1 [L]
#
# Internally rewrite all other .php page requests for all non-www subdomains
# to the requested page, passing subdomain as "user=" parameter
# prevent recursion
RewriteCond %{QUERY_STRING} !^([^&]*&)*user=[^&]+
RewriteCond %{HTTP_HOST} !^www\.example.com
RewriteCond %{HTTP_HOST} ([a-zA-Z0-9]+)\.example.com
RewriteRule ^(.+\.php)$ /$1?user=%1
RewriteCond %{QUERY_STRING} !^([^&]*&)*user=[^&]+
RewriteCond %{HTTP_HOST} !^www\.example.com
RewriteCond %{HTTP_HOST} ([a-zA-Z0-9]+)\.example.com
RewriteRule ^$ /sub_index.php?user=%1 [L]
RewriteCond %{QUERY_STRING} !^([^&]*&)*user=[^&]+
RewriteCond %{HTTP_HOST} !^www\.example.com
RewriteCond %{HTTP_HOST} ([a-zA-Z0-9]+)\.example.com
RewriteRule ^/([A-Za-z0-9_]+\.php)$ /sub_$1?user=%1 [QSA,L]
#######################################################
##### rewrite example.com into www.example.com #####
######################################################
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
###########################
## subdomains
###########################
#index
RewriteCond %{QUERY_STRING} !^([^&]*&)*user=[^&]+
RewriteCond %{HTTP_HOST} !^www\.example.com
RewriteCond %{HTTP_HOST} ([a-zA-Z0-9]+)\.example.com
RewriteRule ^index\.php$ /sub_index.php?user=%1 [L]
#other pages
RewriteCond %{QUERY_STRING} !^([^&]*&)*user=[^&]+
RewriteCond %{HTTP_HOST} !^www\.example.com
RewriteCond %{HTTP_HOST} ([a-zA-Z0-9]+)\.roomres.info
RewriteRule ^([^\.]*)\.php$ /sub_$1.php?user=%1 [QSA,L,R]
#######################################################
##### rewrite example.com into www.example.com #####
######################################################
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
###########################
## subdomains
###########################
RewriteCond %{QUERY_STRING} !^([^&]*&)*user=[^&]+
RewriteCond %{HTTP_HOST} !^www\.example.com
RewriteCond %{HTTP_HOST} ([a-zA-Z0-9]+)\.example.com
RewriteRule ^([^\.]*)\.php$ /sub_$1.php?user=%1 [QSA,L]