Forum Moderators: phranque

Message Too Old, No Replies

VirtualDocumentRoot and RewriteCond and wildcards oh my

Performing -d and using appropriate DocRoot

         

HandyBiteSize

12:51 pm on Jul 30, 2008 (gmt 0)

10+ Year Member



Hi

I've 2 wild card virtualhosts

<VirtualHost *:80>
ServerName www.live.domain.com
ServerAlias *.live.domain.com
VirtualDocumentRoot /var/www/sites/%1/
</VirtualHost>

and
<VirtualHost *:80>
ServerName www.trial.domain.com
ServerAlias *.trial.domain.com
VirtualDocumentRoot /var/www/trialsites/%1/
</VirtualHost>

but i want to share a wildcard ssl cert between them - currently looking like

<VirtualHost *:443>
ServerName *.ssl.subhub.com
SSLEngine on
<snip>
VirtualDocumentRoot /var/www/sites/%1/
</VirtualHost>

but i want to be able to look in /var/www/sites for the %1, use it if it exists or try /var/www/trialsites/%1 if it doesn't

almost like writing....

RewriteCond /var/www/sites/%1 -d
VirtualDocumentRoot /var/www/sites/%1/ [L]
VirtualDocumentRoot /var/www/trialsites/%1/ [L]

Is there ANY way i can do this without moving to a mod_vhost_alias solution? and if not can you point me to good resources for converting what i have to use mod_vhost_alias

jdMorgan

5:43 pm on Jul 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, you could point all of the "sites" to the same DocumentRoot, and then use mod_rewrite to examine the requested HTTP Host and "sort them out" into the proper subdirectories. See the Apache URL Rewriting Guide [httpd.apache.org] entry called "Mass Virtual Hosting" for an example. The code given there can be written in a more-efficient way, but it does serve as an example of one possible approach.

If you will eventually have a large number of 'sites' and they may 'churn' a lot -- with accounts being added and deleted frequently, then consider using RewriteMap to call a small script to access a database file for easier administration and maintenance. There are also many "control panel" solutions as well...

Jim