我刚刚得到了一个全新的Linux服务器(Debian Stable)。 该服务器主要用于虚拟主机和web开发。
我安装了Apache2,PHP5和MySQL,这一切工作。
我组织我的网站的方式是使用以下path:/var/www/username/website.com
现在我不想让服务器自动“创build”/识别子域名。
/var/www/username/sub.website.com> http://sub.website.com
我不想上述事情自动发生。 怎么做?
最好的办法是把链接放到特定目录中的所有网站上,做这样的事情:
<VirtualHost *:80> RewriteEngine On RewriteMap lowercase int:tolower # if already rewitten and we have the right path, stop right here RewriteRule ^(/where/your/sites/are/[^/]+/.*)$ $1 [L] RewriteRule ^(.+) ${lowercase:%{SERVER_NAME}}$1 [C] RewriteRule ^(www\.)?([^/]+)/(.*)$ /where/your/sites/are/$2/$3 [L,E=VHOST_ROOT:/where/your/sites/are/$2/] </VirtualHost>
您可以使用大量虚拟主机 。 在你的情况下,你将无法在主要的apacheconfiguration中使用它,因为path中的“/ username /”,但是你可以为每个用户创build一个虚拟主机,然后在虚拟主机中使用大容量虚拟主机。
例:
<VirtualHost *:80> ServerName domain.tld ServerAlias *.domain.tld VirtualDocumentRoot /var/www/user1/%0/ </VirtualHost> <VirtualHost *:80> ServerName domain2.tld ServerAlias *.domain2.tld VirtualDocumentRoot /var/www/user2/%0/ </VirtualHost> ...
用mod重写你可以让他们把domain.tld改写成指向www目录