步骤:
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)