2

If I have the following Apache configuration and wildcard *. s1.ex.com pointing to the server

<VirtualHost *>
ServerName example.com
DocumentRoot /var/www/example.com
</VirtualHost>

<VirtualHost *>
ServerName example.net
DocumentRoot /home/user2/web/example.net
</VirtualHost>

Is it possible to automatically get the domains example.com.s1.ex.com example.net.s1.ex.com to automatically point to their respective vhost?

Edit: I'm looking for a solution that automatically do the same as if I had added ServerAlias as manually.

3 Answers 3

3

You could add a ServerAlias:

<VirtualHost *>
ServerName example.com
ServerAlias example.com.s1.ex.com
DocumentRoot /var/www/example.com
</VirtualHost>

<VirtualHost *>
ServerName example.net
ServerAlias example.net.s1.ex.com
DocumentRoot /home/user2/web/example.net
</VirtualHost>
3
  • Also note that wildcard characters (* and ?) are allowed in the argument(s) to ServerAlias, so you could even do "ServerAlias example.com.*" and "ServerAlias example.net.*".
    – Xhantar
    Oct 28, 2010 at 2:12
  • I know of ServerAlias. I'm looking for a solution that automatically do the same as if I had added ServerAlias manually.
    – Christian
    Oct 28, 2010 at 10:03
  • Got it. If you have a large number of domains and want it to happen automatically, I'm sure that you can do it with mod_rewrite. Unfortunately, I am not a mod_rewrite expert.
    – Skyhawk
    Oct 28, 2010 at 14:13
0

Are you looking for for mass virtual hosting?

http://httpd.apache.org/docs/current/vhosts/mass.html

http://www.howtoforge.com/how-to-set-up-mass-virtualhosting-with-apache2-mod_rewrite-mod_userdir-mod_suexec-on-centos-5.3

1
  • Maybe. I'm looking for a solution that will automatically add ServerAlias for all VirtualHost in a specific domain (eg. s1.ex.com) and so the DocumentRoot to be anything for the VirtualHost. In practice, it is a temporary domain name while waiting for DNS.
    – Christian
    Oct 28, 2010 at 10:09
0

I think you want mod_vhost_alias.

LoadModule vhost_alias_module /usr/lib/apache2/modules/mod_vhost_alias.so
<VirtualHost *>
  VirtualDocumentRoot /var/www/%-5.0.%-4
</VirtualHost>

example.com.s1.ex.com is now served from /var/www/example.com.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .