配置虚拟主机和伪静态php
1.开启Apache的rewrite模块html
LoadModule rewrite_module modules/mod_rewrite.soweb
2.开启虚拟主机功能服务器
# Virtual hosts
Include conf/extra/httpd-vhosts.confide
3.修改conf/extra/httpd-vhosts.conf文件spa
<VirtualHost *:80>htm
DocumentRoot "F:/wamp/www/Teacher" 指定访问目录
ServerName www.baidu.com 指定容许访问的域名
<Directory "F:/wamp/www/Teacher"> 对这个目录进行设置继承
Deny from all 禁止任何人访问,不写能够访问,是由于若是此目录没作设置,会继承他的上级目录来权限;若是上级目录禁止访问,能够再此目录中写Allow from all则这个目录就能够访问,不会继承父目录的权限域名
Options none 不容许服务器显示目录中的文件列表,容许就改为Options indexesit
DirectoryIndex abc.html 123.html 配置目录指定首页面,默认是index,指定后先选择abc.html,若是没有再显示123.html
errorDocument 404 /404.html 指定发生错误后显示的页面,errorDocument后跟HTTP状态码,当遇到这种状态吗,就会执行后面指定的页面
allowoverride all 容许到对应目录的.htaccess文件中 读取规则
下面配置rewrite规则
RewriteEngine On 开启从新功能(必定要检测是否启用mod_rewrite.so模块)
RewriteRule a.html b.php 当访问a.html页面时,实际上是访问b.php
RewriteRule news/id/(\d+).html news.php?id=$1 为了普遍的使用,可使用正则来匹配news/id/100.html这种都执向news.php,接收的参数就是前面匹配的数值
</Directory>
</VirtualHost>
4.htaccess文件的写法
在没有权限修改httpd-vhosts.conf文件的状况系下,可使用.htaccess文件来作目录权限,若是.htaccess用不了,就看看httpd-vhosts.conf文件是否开启了allowoverride all
<IfModule rewrite_module> #若是加载了rewrite_module模块
这些规则和 httpd-vhosts.conf文件中的规则写法同样
RewriteEngine On
RewriteRule news/id/(\d+).html news.php?id=$1
能够写多条规则
</IfModule>
5.作防盗链
<IfModule rewrite_module>
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?xuni.com(/)?.*$ [NC]
RewriteRule .*\.(gif|jpg|jpeg|bmp|png)$ http://www.xuni.com/warning.xjpg [R,NC]
</IfModule>
6.在C:\Windows\System32\drivers\etc的host文件中添加域名指向到本地127.0.0.1 www.xuni.com
注意:在配置好后,打开localhost发现提示403错误,是由于开启了虚拟主机功能(第二步),在httpd-vhosts.conf文件中默认添加了几条规则,由于用的是Wamp环境,里面的DocumentRoot不是Wamp指定的根目录,致使localhost定位到的目录不对,这就是致使localhost不能访问403的缘由,只要把默认的规则修改下
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "f:/wamp/www" #访问的根目录
ServerName localhost #容许访问的域名
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
而后在后面添加本身须要的规则