配置虛擬主機和僞靜態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>
而後在後面添加本身須要的規則