If you manage many websites on a Apache web server,you may need this to save your time and also the server’s memory.Think about you have 10K website(virtual hosts), you would never like to write the configuration for each virtual host.The Apache configuration file will be huge which my contain about 70k lines (10k multiply 7 ). This will also slow down the Apache web server start speed.
Setting up mass virtual host will dynamically create virtual hosts without any configuration.You don’t need to restart the Apache web server.The only thing you need to do is create a folder in the specified folder and add a dns record.
let’s take a look at how to setting up mass virtual host.
mod_vhost_alias has a config directive VirtualDocumentRoot which dynamically configure the location of the document root for a given virtual host.it allows you to determine where Apache will find your documents based on the value of the server name.
UseCanonicalName Off
VirtualDocumentRoot /var/www/vhost/%2+/
A request to http://www.example.com/ will be served by /var/www/host/example.com/,request to http://www.example.com/page/test.html will be parsed as /var/www/host/example.com/page/test.html
however,with the configuration above is not enough,for request to http://example.com/page/test.html will be served by /var/www/host/.com/page/test.html.This will lead to 404 error page as the file is not existed.
You need to redirect all request to none www domain too its long format www.domain.com.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
So,i config my apache with the following configuration and it work very well.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
<Directory “/var/www/vhost”>
AllowOverride ALL
</Directory>
VirtualDocumentRoot /var/www/vhost/%2+/