eddie vanson
18th December 2008, 10:36
I would like to enable ad-hoc subdomains on my Apache based server. In other words, I'm after a setup where all I have to do create a new subdomain is create a new directory on the server.
My desired file structure is like this
/var/sites/example.com/public/www/...
/var/sites/example.com/public/foo/...
/var/sites/example.com/public/bar/...
My document root is /var/sites/example.com/public/
When I enter "http://foo.example.com" in a browser, I'd like to serve the contents of /var/sites/example.com/public/foo, but I still want the URL in the browser to read "http://foo.example.com".
I have already setup my dns so that any URL of the form *.example.com get routed to my server.
I have tried using mod_rewrite but don't seem to be able to get the voodoo right. The closest I can get is configuring my .htaccess file thusly:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule (.*) http://example.com/%1 [L]
</IfModule>
This serves the correct page, but redirects the browser from "http://foo.example.com" to "http://example.com/foo".
Any pointers appreciated.
My desired file structure is like this
/var/sites/example.com/public/www/...
/var/sites/example.com/public/foo/...
/var/sites/example.com/public/bar/...
My document root is /var/sites/example.com/public/
When I enter "http://foo.example.com" in a browser, I'd like to serve the contents of /var/sites/example.com/public/foo, but I still want the URL in the browser to read "http://foo.example.com".
I have already setup my dns so that any URL of the form *.example.com get routed to my server.
I have tried using mod_rewrite but don't seem to be able to get the voodoo right. The closest I can get is configuring my .htaccess file thusly:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule (.*) http://example.com/%1 [L]
</IfModule>
This serves the correct page, but redirects the browser from "http://foo.example.com" to "http://example.com/foo".
Any pointers appreciated.