Dynamic vhosts and combined directories (Apache 2.2)
Lets take "domain.com" as an example.
(This is what I want to happen, not how it works right now)
domain.com redirects to
subdomain.domain.com reads from /subdomain.domain.com
I don't want to set up VirtualHosts for every single domain/subdomain, but I'm starting to think this is the only way. A lot of examples uses VirtualDocumentRoot /%0- and that would work for the subdomains but not domain.com as it would result in apache looking for /
Is what I'm trying to do possible or am I just trying to be much too dynamic for no good reason?
4 Replies
ServerAlias www.domain.com
Other stuff in here as required
````
Should get the first bit happening for you.
../sites-available/default looks like this:
DocumentRoot /sites
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<directory sites="">Options ExecCGI -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
AddHandler fcgid-script .php
FCGIWrapper /usr/lib/cgi-bin/php5 .php</directory>
NameVirtualHost *:80
<virtualhost *:80="">DocumentRoot /sites/default/public_html</virtualhost>
And then for each domain I do this:
<virtualhost *:80="">ServerName domain.com
ServerAlias www.domain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule (.*) http://www.domain.com [R=301,L]
DocumentRoot /sites/domain.com/public_html</virtualhost>
<virtualhost *:80="">ServerName domain.com
ServerAlias *.domain.com
VirtualDocumentRoot /sites/%0/public_html</virtualhost>
Could probably be applied to other distributions
@OverlordQ:
http://gentoo-wiki.com/ApacheModulesmodvhostalias Could probably be applied to other distributions
Thanks for the link, the problem with that one is that example.com andwww.example.com gets their own directories.
Too bad you can't do if (%-3.0 == "www") { $dir == "non-www-dir")