This is a discussion on Vhost_alias & more within the Linux Web Servers forums, part of the Web Server and Related Forums category; Hi, I'm trying to set up on an apache 2.0 server the following configuration: http://mydomain.net => /...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I'm trying to set up on an apache 2.0 server the following configuration: http://mydomain.net => /home/mydomain.net/_ http://www.mydomain.net => /home/mydomain.net/www http://sub1.mydomain.net => /home/mydomain.net/sub1 http://sub2.mydomain.net => /home/mydomain.net/sub2 http://*.mydomain.net => /home/mydomain.net/_ I can do that with several <VirtualHost> with different ServerName, but I don't want annoyed me by adding a new directive for each subdomain. I've tried the VirtualDocumentRoot in that way: VirtualDocumentRoot /home/mydomain.net/%-3+ and it works pretty good for existing subdomain, but I've got an 404 error for other domain. So how can I keep this setting but redirecting unexisting subdomain (no folder in /home/mydomain.net/) to a default one ? Regards, Matthieu |
|
|||
|
Matthieu <news@plouk.net> wrote in news:43c0f55a$0$21206
$626a54ce@news.free.fr: > Hi, > > I'm trying to set up on an apache 2.0 server the following configuration: > > http://mydomain.net => /home/mydomain.net/_ > http://www.mydomain.net => /home/mydomain.net/www > http://sub1.mydomain.net => /home/mydomain.net/sub1 > http://sub2.mydomain.net => /home/mydomain.net/sub2 > http://*.mydomain.net => /home/mydomain.net/_ > > I can do that with several <VirtualHost> with different ServerName, but > I don't want annoyed me by adding a new directive for each subdomain. > > I've tried the VirtualDocumentRoot in that way: > VirtualDocumentRoot /home/mydomain.net/%-3+ > and it works pretty good for existing subdomain, but I've got an 404 > error for other domain. > So how can I keep this setting but redirecting unexisting subdomain (no > folder in /home/mydomain.net/) to a default one ? I personally wouldn't clutter up the home directory with resources devoted to virtual hosts. It makes more sense to logically separate them in a single directory: /var/www/hosts/example.com /var/www/hosts/www.example.com /var/www/hosts/support.example.com Then, to use simplified mass virtual hosting, you could put this in a single VirtualHost directive: VirtualDocumentRoot /var/www/hosts/%0/site This will match the host in the request, and automatically serve its pages. For example: http://www.example.com/index.html would represent this file: /var/www/hosts/www.example.com/site/index.html If you want to use the same files for different hosts, just create symlinks: ln -s /var/www/hosts/www.example.com /var/www/hosts/example.com As for directing hosts that have no configuration in apache (but resolve to the same IP) to a default set of pages, you might be able to specify a default IP-based virtual host before your name-based ones: NameVirtualHost * <VirtualHost 192.168.1.2> ServerName example.com DocumentRoot /var/www/hosts/example.com/site </VirtualHost> <VirtualHost *> VirtualDocumentRoot /var/www/hosts/%0/site UseCanonicalName Off </VirtualHost> There are pros and cons to this scenario. Mass virtual hosting is convenient because configuration only requires a DNS record to be added. Use of a default host to catch all other requests to the IP can be handy when dealing with probes, but I probably wouldn't use it for anything important. Finally, pointing multiple names to the same set of pages can dilute your search engine rankings. YMMV. |