Forum Moderators: phranque
Directory: c:\vhosts\user1
Directory" c:\vhosts\user2
so when users type user1.example.com or example.com/user1 , Apache reads the content of user1 and if someone types user2.example.com or example.com/user2, Apache reads the user2 directory.
1) [httpd.apache.org ]
2) Listed at [httpd.apache.org ], under 'Mass Virtual Hosting'.
The catch to these solutions is that you become somewhat limited in the number of per-site customizations you can do. Of course, in large-scale environments, this problem is generally self-correcting; solutions are found that don't require customizations, or the system has a habit of collapsing under its own weight. At a former job, I ran server that hosted ~9000 domains or so, using a variation on method #2 above.
As a final note, when the number of VirtualHosts gets REALLY large, you run into a technical issue (rather than simple administrative ones. For some value of 'simple' =) ); Apache allocates a block of memory for each <VirtualHost> container. When you start getting thousands of these, Apache's memory footprint grows significantly, which can be an issue *especially* when using Apache in pre-fork mode (I believe the win32 version of Apache uses a threaded model, yes? In which case, you may be less affected by this, as would users of Apache 2 in threaded mode).
my directory structure is this:
c:\apache\htdocs <----- server root
c:\apache\htdocs\members\user1 <---- user1 root
c:\apache\htdocs\members\sub1 <---- subdomain root
I am testing it on a Fresh install of apache 2.05. Server port is set to 8080 and Listen port is 8080 as well.
my vhost.map
www.example.com:8080 c:/apache/htdocs/members/user1
sub.mydomain.com:8080 c:/apache/htdocs/subdomains/sub1
new content added to htdocs:
RewriteEngine on
RewriteMap lowercase int:tolower
# define the map file
RewriteMap vhost txt:c:/apache/conf/vhost.map
# deal with aliases as above
RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
# this does the file-based remap
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/docs/$1
RewriteCond %{REQUEST_URI} ^/cgi-bin/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/cgi-bin/$1
username.domain.com
?
If so, you could do something like this:
RewriteEngine on
#
# place the "username" portion of
# "username.domain.com" into %1
RewriteCond %{HTTP_HOST} ^([^\.]+)\.
#
# place the requested path into $1 and Rewrite
RewriteRule ^/(.*) c:\vhosts\%1\$1 [L]