配置Apache httpd server 2.2 Virtual Host:
最简单的方法:
一、打开httpd.conf,找到:
#Include conf/extra/httpd-vhosts.conf
取消这一行的注释,即删除前面的#
二、打开 conf/extra/httpd-vhosts.conf
比如要添加一个 uri 为 local.weitwo.com的virtual host,映射到本机的80端口,那么修改或者复制example中的<VirtualHost></VirtualHost>节点,
修改其中的ServerName为 local.weitwo.com 即可
<VirtualHost *:80>
ServerAdmin t@local.weitwo.com
DocumentRoot "D:/Project/PHP/WeiTwoWebsite"
ServerName local.weitwo.com
ErrorLog "logs/local.weitwo.com.log"
CustomLog "logs/t.weitwo.com-access.log" common
</VirtualHost>
ServerAdmin t@local.weitwo.com
DocumentRoot "D:/Project/PHP/WeiTwoWebsite"
ServerName local.weitwo.com
ErrorLog "logs/local.weitwo.com.log"
CustomLog "logs/t.weitwo.com-access.log" common
</VirtualHost>
然后再修改本机的host文件, 位于system32/driver/etc下,增加: 127.0.0.1 local.weitwo.com
此时即可在本机访问local.weitwo.com了
二、为VirtualHost添加 url rewrite
1.在httpd.conf中,找到如下行
#LoadModule rewrite_module modules/mod_rewrite.so
取消其注释,即删除前面的“#”
2.在VirtualHost中,添加Directory节点,指定AllowOverride为All,如果你想通过.htaccess中写rewrite规则,就不需要再做什么了,如果你想直接在conf文件中写rewrite rule,直接在Directory节点中写rewrite规则即可。
最终的VirtualHost像下面这样:
<VirtualHost *:80>
ServerAdmin t@local.weitwo.com
DocumentRoot "D:/Project/PHP/WeiTwoWebsite"
ServerName local.weitwo.com
ErrorLog "logs/local.weitwo.com.log"
CustomLog "logs/t.weitwo.com-access.log" common
<Directory "D:/Project/PHP/WeiTwoWebsite">
#Options Indexes FollowSymLinks
AllowOverride All
#RewriteEngine on
#RewriteRule ^c.php$ a.html
</Directory>
</VirtualHost>
ServerAdmin t@local.weitwo.com
DocumentRoot "D:/Project/PHP/WeiTwoWebsite"
ServerName local.weitwo.com
ErrorLog "logs/local.weitwo.com.log"
CustomLog "logs/t.weitwo.com-access.log" common
<Directory "D:/Project/PHP/WeiTwoWebsite">
#Options Indexes FollowSymLinks
AllowOverride All
#RewriteEngine on
#RewriteRule ^c.php$ a.html
</Directory>
</VirtualHost>
记录之。
点个广告: