liang183 发表于 2016-12-6 17:57:27

Apache无限二级域名配置方案

要做到无限二级域名,第一步必须要做的是把域名泛解析,然后根据需求修改配置文件情景一需求:www.a.com使用g:/www/www.a.com/bbs.a.com使用g:/www/bbs.a.com/shanghai.a.com使用g:/www/city.a.com/shangehai/beijing.a.com使用g:/www/city.a.com/beijing/解决方案:在apache配置文件加NameVirtualHost *:80<VirtualHost *:80>DocumentRoot "G:/www/www.a.com"ServerName www.a.com</VirtualHost><VirtualHost *:80>DocumentRoot "G:/www/bbs.a.com"ServerName bbs.a.com</VirtualHost><VirtualHost *:80>DocumentRoot "G:/www/city.a.com"ServerName city.a.comServerAlias *.a.comrewriteengine onrewritecond %{HTTP_HOST} ([^(www|bbs|city)][^.]+)\.a\.com$rewriterule ^(.+)$ %{HTTP_HOST}$1 rewriterule ^([^.]+)\.a\.com(.*)$ /$1$2</VirtualHost>注意:city.a.com虚拟主机要写在后面,让www和bbs优先级更高。这个方案也可以达到配置一次,以后目录即建即用。情景二需求:www.a.com使用g:/www/www.a.com/bbs.a.com使用g:/www/bbs.a.com/shanghai.a.com使用g:/www/city.a.com/beijing.a.com使用g:/www/city.a.com/解决方案:在apache配置文件加NameVirtualHost *:80<VirtualHost *:80>DocumentRoot "G:/www/www.a.com"ServerName www.a.comServerAlias www.a.com</VirtualHost><VirtualHost *:80>DocumentRoot "G:/www/bbs.a.com"ServerName bbs.a.comServerAlias bbs.a.com</VirtualHost><VirtualHost *:80>DocumentRoot "G:/www/city.a.com"ServerName city.a.comServerAlias *.a.com</VirtualHost>注意:city.a.com虚拟主机要写在后面,让www和bbs优先级更高。
页: [1]
查看完整版本: Apache无限二级域名配置方案