For small number of virtual hosts (vhosts) we can use the “VirtualServer” directive in apache web server. Unfortunately when we have high number of vhosts (hundreds), it gets very complicated to maintain such configuration. The reasons are:
- it is complicated to add and remove virtual hosts (either to a single conf file or in multiple files inside vhosts.d directory);
- You must restart the server every time a new virtual host is added/removed;
- Each virtual host eats usually 2 file handlers (access_log and error_log).
Then mod_rewrite is the right way to follow. mod_rewrite is more complicated as traditional VirtualServer configuration but if you master it, it provides seamless possibilities.
- Apache 1.3.x – Dynamically configured mass virtual hosting – Using a separate virtual host configuration file
- Apache 1.3.x – Module mod_rewrite
- http://httpd.apache.org/docs/1.3/misc/rewriteguide.html – search for “Mass Virtual Hosting” part
Mass Apache Virtual Hosting using mod_rewrite