Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- Mod rewrite for subdomains


extras - 7:33 pm on Jan 21, 2006 (gmt 0)


The backref \1 in this part doesn't work in the newer version fo Apache1.3, AFAIK.
rewritecond %2<->%3_SPACE_!^(.*)<->\1$ [NC]

I think it worked up to Apache 1.3.27 or so.

I wrote several different version of sub (and pointed) domain RewrireRules.

Here is one of them.

RewriteEngine on
RewriteBase /

# Loop stopping and Virtual document root processing for CGI/PHP
#RewriteRule ^/*virtualdr.cgi - [L]
#RewriteRule ^/*[^./]+\.[^/]+/.*\.(cgi¦php5?)$ virtualdr.cgi [L]
RewriteRule ^/*[^./]+\.[^/]+/.*$ - [L]

# Code for missing Trailing slashe problem
RewriteCond s%{HTTPS} ^((s)on¦s.*)$
RewriteRule ^/*(.+/)?([^.]*[^/])$ http%2://%{HTTP_HOST}/$1$2/ [L,R=301]

# Sub/pointer domain rewrite code
RewriteCond %{HTTP_HOST}!^(www\.)?(MAINDOMAIN\.?COM¦USER) [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ [NC]
RewriteRule ^(.*)$ %2/$1


Directory layout:
/path-to-docroot/ <== MainDomain in docroot
/path-to-docroot/subdom1.maindomain.com/ <== Directory for sub domain
/path-to-docroot/subdom2.maindomain.com/ <== Directory for sub domain
/path-to-docroot/pointed-domain.com/ <== Directory for pointed domain
/path-to-docroot/sub.pointed-domain.com/ <== Directory for sub domain of pointed domain

The virtualdr.cgi prevents the problem of ugly URL and
some scripts simply failing when the docroot is presented differently.

I'll post URL for this and other code and explanation.
if it's allowed
If not, you can google and it appears near the top with "virtualdr.cgi".


Thread source:: http://www.webmasterworld.com/apache/5376.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com