We Recommend

Mastering Regular Expressions Mastering Regular Expressions
As this book shows, a command of regular expressions is an invaluable skill. Regular expressions allow you to code complex and subtle text processing that you never imagined could be automated. Regular expressions can save you time and aggravation. They can be used to craft elegant solutions to a wide range of problems. Once you've mastered regular expressions, they'll become an invaluable part of your toolkit. You will wonder how you ever got by without them.


Ballyhoo


Posted By

fris on 11/16/07


Tagged


Versions (?)


Who likes this?

9 people have marked this snippet as a favorite

nicolaspar
copyleft
adix
liqweed
naz
jimmayes
wbowers
gAmUssA
orhanveli


create subdomains on the fly with modrewrite


Published in: Regular Expression 


  1. Options +FollowSymLinks
  2.  
  3. RewriteEngine On
  4.  
  5. RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
  6. RewriteCond %{HTTP_HOST} ^(.*\.)?([^\.]+)\.domain\.com$ [NC]
  7. RewriteCond %{DOCUMENT_ROOT}/subs/%2%{REQUEST_URI}/ -d
  8. RewriteRule [^/]$ http://%2.domain.com%{REQUEST_URI}/ [R=301,L]
  9.  
  10. RewriteCond %{HTTP_HOST} ^.*\.([^\.]+\.domain\.com)$ [NC]
  11. RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  12.  
  13. # abc.domain.com --> /subs/abc/
  14.  
  15. RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
  16. RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
  17. RewriteCond %1:::%{REQUEST_URI} !^(.+):::/subs/\1(/.*)?$ [NC]
  18. RewriteCond %{DOCUMENT_ROOT}/subs/%1/ -d
  19. RewriteRule ^(.*)$ /subs/%1/$1 [QSA,L]

Report this snippet 

You need to login to post a comment.