httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Skwar <>
Subject Subdomains with mod_rewrite
Date Sun, 03 Mar 2002 09:29:42 GMT
Hello all!

I'd like to setup my Apache 1.3.23 so, that it translates subdomain
requests to directories automagically.  Let me give you some examples
(the domain name is dom.ain):

Request                                 Redirect
a) http://dom.ain                       No redirect
b) http://sub.dom.ain                   http://dom.ain/sub
c) http://foo.sub.dom.ain               http://dom.ain/sub/foo
d)           http://dom.ain/sub/foo/bar
e)      http://dom.ain/sub/foo/bar/blah

This means, that if one subdomain is requested, Apache should look for
the files in a folder with the same name as the subdomain (case a)
*sub*.dom.ain -> dom.ain/*sub*).

If two or more subdomains are requested, for the lookup it should
reverse the order of the domainnames and change the '.' to '/' to get
directory delimiters (cases c) to e)).

However, if the HTTP_HOST starts with www., the www. should be ignored
for all the translations.

For the most simple case a) I've got the following rules:

RewriteCond     %{HTTP_HOST}    ^[^.]+\.dom\.ain$
RewriteRule     ^(.+)   %{HTTP_HOST}$1  [C]
RewriteRule     ^([^.]+)\.dom.ain(.*)   /var/www/html/$1/$2

Well, could somebody please help me with the cases c) to e)?

Thanks a lot,

Alexander Skwar
How to quote: (german) (english)
Homepage:      |     Jabber: - Die g√ľnstige Art an Linux Distributionen zu kommen
                       Uptime: 1 day 0 hours 39 minutes

The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message