Forum Moderators: phranque
I would like everything matching /^\w\w\.widgets\.com$/i go to the same DocumentRoot. Is it possible?
Current settings:
<VirtualHost *:80>
ServerAdmin webmaster@widgets.com
ServerName www.widgets.com no.widgets.com fi.widgets.com dk.widgets.com ..... ru.widgets.com
DocumentRoot /opt/widgets/public_html
</VirtualHost>
<VirtualHost *>
ServerName example1.com
DocumentRoot /example1/rest
</VirtualHost>
#
<VirtualHost *>
ServerName aa.example1.com
DocumentRoot /example1/aa
</VirtualHost>
#
<VirtualHost *>
ServerName www.example1.com
DocumentRoot /example1/
</VirtualHost>
The requests would have been served by the following VirtualHosts:
www.example1.com -> 3rd
aa.example1.com -> 2nd
ru.example1.com -> 1st
qw.example1.com -> 1st
BUT!
wqerty.example1.com -> 1st
dummy.com -> 1st
So the 1st VirtualHost processes everything which is not matched by the other VirtualHosts. The next step is to make sure that it only processes the requests you need, the ones for the xx.example1.com hosts. Practically we do the opposite, we send away requests which should not processed by that VirtualHost.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^([a-z]{2})\.example1\.com(:[0-9]+)?$ [NC]
RewriteRule ^/ h**p://www.example1.com/nosuchhost.html [R=301,L]
RewriteRule ^/ - [G,L]
So the final result is something like this:
www.example1.com -> 3rd
aa.example1.com -> 2nd
ru.example1.com -> 1st
qw.example1.com -> 1st
wqerty.example1.com -> Redirected to the 3rd
dummy.com -> Redirected to the 3rd
Have fun