关于apache配置虚拟主机
最近看了下Apache配置虚拟主机,主要有三个步骤
1、在Apache中的httpd.conf里面开启httpd.vhost模块,也就是把这个模块挂载在httpd.conf中
2、在httpd.vhost里面写入
<VirtualHost *:80> DocumentRoot "E:/a" ServerName a.com <Directory "E:/a"> #Options +indexes Order Allow,Deny Allow from all </Directory> </VirtualHost>
3、在c盘系统盘里面找到 host文件,把 127.0.0.1 a.com写入文件里面,重新启动Apache
关于第二代配置这里讲解下
DocumentRoot "E:/a" ServerName a.com
这两行必须,它说明了网站目录跟 网站域名地址
而Order Allow Deny则说明先看允许的,在看不允许的,下面的 Allow from all 则允许全部,如果想禁止某个 则可以使用 Deny 192.168.1.100类似地址
还可以在后面加入
RewriteEngine On RewriteRule ([a-z]+)/([a-z]+)/(\d+)\.html$ showNew.php?ctr=$1&fn=$2&id=$3 DirectoryIndex a.txt ErrorDocument 404 http://a.com/test.html
第一行说明开启重写模块
第二行是重写的规则 重写的规则是使用正则表达式
RewriteRule ([a-z]+)/([a-z]+)/(\d+)\.html$ showNew.php?ctr=$1&fn=$2&id=$3
上一行的意思是如果浏览器碰到 ([a-z]+)/([a-z]+)/(\d+)\.html$ 这个规则的路径 如 Index/login/2.html
则让Apache去 showNew.php?ctr=Index&fn=login&id=2 的动态文件,也就是伪静态技术
这里的正则表达式使用了 子表达式([a-z]+),捕获,方向引用($1 代表第一个子表达式)
DirectoryIndex a.txt 这一行说明如果访问 a.com这个域名,这直接指向 a.txt 这个文件
ErrorDocument 404 http://a.com/test.html 这里指明了如果出现404则跳转到 test.html 这里需要写全域名,即 http://a.com/test.html 如果是/test.html则不能成功跳转指向。