I am looking for Apache configuration that would allow for the following:
- Serve sub.domain.com as
/%docRoot%/domain.com/sub, and - Would be able to do this for every hosted domain and any subdomain (ie. no per-domain vhost configuration)
I would be grateful for any solution, especially if there was no mod_rewrite involved (using mod_vhost_alias).
Note: There are some obvious solutions using mod_vhost_alias, but they either work for domain.com or sub.domain.com, none of them seems to cover both cases.
Have a nice day!
Point
*.domain.comto your document root (/%docRoot%/). You’ll need to do this in a vhost config. In that same vhost, add this:If you want to avoid pointing
www.domain.comto/%docRoot%/domain.com/www, then add a condition to exclude it:EDIT:
Yes, the above will only do the routing for
domain.com, if you want to do this for all arbitrarydomain.com, you’ll need to do something a bit more tricky:The tricky thing here is the
%{REQUEST_URI}:%2/%1 !^/([^/]+/[^/]+)[^:]*:\1match. It posits the condition:%{REQUEST_URI}:domain.com/suband makes sure the%{REQUEST_URI}doesn’t start with thedomain.com/sub(back refrenced from previous match using %2/%1) using the\1back reference.With this, you setup your vhost to accept every domain (default vhost) and any subdomain/domain will get routed. Examples:
http://blah.bleh.org/file.txtgoes to/%docRoot%/bleh.org/blah/file.txthttp://foo.bar.com/some/path/goes to/%docRoot%/bar.com/foo/some/path/http://sub2.sub1.d.com/index.htmlgoes to/%docRoot%/sub1.d.com/sub2/index.htmlEDIT2:
Try these:
Basically the same thing, except a few of the regex needs to be tweaked to separate what a
domain.comis like vssub.domain.com. If you want to redirectwww.domain.comtodomain.com, that needs to happen before these rules.