步驟:
1.開啓apache Rewrite_mod模塊。
httpd.conf106H 去掉 LoadModule rewrite_module modules/mod_rewrite.so之前的#
2.在配置文件末尾添加虛擬主機配置
以上相關選項根據自己項目的存放目錄進行相關修改
重新啓動apache
3.在項目根目錄下新建.htaccess文件
只需要添加相關RewriteRule就可以
上面寫到的RewriteRule ^([a-zA-Z]+)//([a-zA-Z0-9]+)/.shtml$ $1.php?id=$2 [L]
實現了http://www.test.test/test/3.shtml 實際URL http://www.test.test/test.php?id=3
在頁面頭部添加base標籤 防止因爲圖片路徑爲相對路徑導致URL重寫後不能取得圖片
<base href="http://localhost/"/><!--確保整個頁面的相對地址都是在BASE路徑下展開的不管移動到哪-->
或者
RewriteCond %{REQUEST_URI} !^.*(/.xml|/.html|/.htm|/.php|/.swf|/.css|/.js|/.gif|/.png|/.jpg|/.jpeg)