| Author |
Message |
tozz
Joined: 28 Nov 2007
Posts: 5
Location: San Francisco, CA
|
| Posted: Mon Dec 03, 2007 9:01 pm Post subject: Dynamic vhosts and combined directories (Apache 2.2) |
|
|
I have an old account on with a provider that gives me the opportunity to redirect non-www requests to their www counterparts (without doing it with .htaccess files). I want to mimic that option.
Lets take "domain.com" as an example.
(This is what I want to happen, not how it works right now)
domain.com redirects to www.domain.com but reads from /domain.com (same as domain.com would without the re-direct).
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 /www.domain.com
Is what I'm trying to do possible or am I just trying to be much too dynamic for no good reason? |
|
| Back to top |
|
kangaby
Joined: 20 Oct 2004
Posts: 62
|
| Posted: Tue Dec 04, 2007 3:53 am Post subject: |
|
|
Code: <VirtualHost ip:80>
ServerName domain.com
ServerAlias www.domain.com
Other stuff in here as required
</VirtualHost>
Should get the first bit happening for you. |
|
| Back to top |
|
tozz
Joined: 28 Nov 2007
Posts: 5
Location: San Francisco, CA
|
| Posted: Tue Dec 04, 2007 12:16 pm Post subject: |
|
|
Looks like the direction I was heading myself, this is how I've currently set it up, any sugestions are welcome.
../sites-available/default looks like this:
Code: 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:
Code: <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>
|
|
| Back to top |
|
OverlordQ
Joined: 04 Jun 2004
Posts: 200
|
| Posted: Tue Dec 04, 2007 7:55 pm Post subject: |
|
|
http://gentoo-wiki.com/Apache_Modules_mod_vhost_alias
Could probably be applied to other distributions |
|
| Back to top |
|
tozz
Joined: 28 Nov 2007
Posts: 5
Location: San Francisco, CA
|
| Posted: Wed Dec 05, 2007 12:10 pm Post subject: |
|
|
OverlordQ wrote: http://gentoo-wiki.com/Apache_Modules_mod_vhost_alias
Could probably be applied to other distributions
Thanks for the link, the problem with that one is that example.com and www.example.com gets their own directories.
Too bad you can't do if (%-3.0 == "www") { $dir == "non-www-dir")
;) |
|
| Back to top |
|
| |