Forum Moderators: phranque

Message Too Old, No Replies

rewrite, virtual hosting issue

         

japhar

1:36 pm on Jun 1, 2008 (gmt 0)

10+ Year Member



Howdy,

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}&#166;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/&#166;/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 ?

jdMorgan

3:57 pm on Jun 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unless you specify a ServerName in the first vHost container, it will apply to *all* requests.

Jim