Forum Moderators: phranque
I've setup virtual hosting using this code:
<VirtualHost ip_address_here>
RewriteEngine on
RewriteMap lowercase int:tolower
RewriteMap vhost txt:/etc/apache2/hosting/vhost.map
RewriteCond %{HTTP_HOST} !^$
RewriteCond ${lowercase:%{HTTP_HOST}¦NONE} ^(www\.)?(.+)$
RewriteCond ${vhost:%2} ^(/.*)$
RewriteRule ^/(.*)$ %1/$1 [E=VHOST:${lowercase:%{HTTP_HOST}}]
</VirtualHost>
vhost.map contains:
mydomain.com /path/to/serve
mydomain2.com /path/to/serve2
And it works fine.
The problem is, that i need to setup few domains using this code:
(to enable, subdomains creation)
<VirtualHost ip_address_here>
ServerName anotherdomain.com
ServerAlias *.anotherdomain.com
DocumentRoot /path/to/serve/this/domain
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.anotherdomain\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.anotherdomain\.com [NC]
RewriteRule ^/(.*)$ - [E=subdir:%2,E=URIreq:$1,C]
RewriteCond %{DOCUMENT_ROOT}/sub/%{ENV:subdir} -d
RewriteRule !^/sub/ /sub/%{ENV:subdir}/%{ENV:URIreq} [L]
RewriteRule ^(sub) - [L]
RewriteCond %{REQUEST_URI} !^/html/¦/cgi-bin/
RewriteRule ^/(.*)$ /html/$1 [L]
</VirtualHost>
Unfortuantely, this doesnt work when both those <VirtualHost> block are used.
Any ideas how to make it work ? I have only 1 ip address. Is it possible ?