All pastes #124082 Raw Edit

Something

public text v1 · immutable
·published 2006-08-09 20:26 UTC
rendered paste body
RewriteEngine on
RewriteLog /usr/local/apache/logs/rewrite.log
RewriteLogLevel 9
RewriteMap      lc              int:tolower
#if www.example.com end and go to www.example.com
RewriteCond   %{HTTP_HOST}                 ^(www\.)?example\.com$ [NC]
RewriteRule   ^(.+)             - [L]

#if www.foo.example.com 301 to foo.example.com - THIS ONE'S IMPORTANT
#I honestly don't know what the 2nd or 3rd lines of this section do
RewriteCond   %{HTTP_HOST}                 ^www\.[^.]+\.example\.com$ [NC]
RewriteRule   ^(.+)                        %{HTTP_HOST}=$1 [C]
RewriteRule   ^(.*)=(.*)                   ${lc:$1}$2 [C]
RewriteRule ^www\.([^.]+)\.example\.com http://$1.example.com/ [R=301,L]

#these last 3 lines are to rewrite foo.example.com/something to www/example.com/foo/something
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/icons
RewriteCond %{REQUEST_URI} ^.*[^/]$
RewriteCond /www/example.com/%1%{REQUEST_URI} -d
RewriteRule (.*) /www/example.com/%1$1/ [L]

RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/icons
RewriteRule (.*) /www/example.com/%1$1