View Single Post
Old 05-16-2011, 08:17 AM  
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,243
htaccess/modrewrite help

anyone use htaccess to create sub domains on the fly?

i want to make it so if i am viewing a directory listing, when clicking on parent directory it goes back to the root of the sub domain, not the domain/subs/name.

here is my htaccess.

Code:
# disable direct access to .htaccess

<Files .htaccess>
 order allow,deny
 deny from all
</Files>

# disable direct access to other files

<FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
 Order Allow,Deny
 Deny from all
</FilesMatch>

# cache images and flash content for one month

<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>

# cache text, css, and javascript files for one week

<FilesMatch ".(js|css|pdf|txt)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>

# cache html and htm files for one day

<FilesMatch ".(html|htm)$">
Header set Cache-Control "max-age=43200"
</FilesMatch>

# enable symbolic links
Options +FollowSymLinks

# lets use some rewrites

RewriteEngine On

# remove www

RewriteCond %{HTTP_HOST} ^www\.(domain\.com)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# treat .php as .html
# example: /downloads/files.php will work as /downloads/files.html

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^(/.+\.)html$ [NC]
RewriteCond %{DOCUMENT_ROOT}%1php -f
RewriteRule \.html$ %1php [NC,QSA,L]

# images on the root.
# example /images/chicago.jpg will work as /chicago.jpg

RewriteCond %{DOCUMENT_ROOT}/images%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/images%{REQUEST_URI} -d
RewriteRule !^images(/.*)?$ /images%{REQUEST_URI} [QSA,L]

# sub domains on the fly

RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*\.)?([^\.]+)\.domain\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/subs/%2%{REQUEST_URI}/ -d
RewriteRule [^/]$ http://%2.domain.com%{REQUEST_URI}/ [R=301,L]
RewriteCond %{HTTP_HOST} ^.*\.([^\.]+\.domain\.com)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteCond %1:::%{REQUEST_URI} !^(.+):::/subs/\1(/.*)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/subs/%1/ -d
RewriteRule ^(.*)$ /subs/%1/$1 [QSA,L]
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote