利用.htaccess文件对PHP网站或文件进行伪静态处理

一、检查服务器是否支持伪静态处理:

必 须要空间支持 Rewrite 以及对站点目录中有.htaccess 的文件解析,才有效.找到apache安装目录下的httpd.conf文件,去掉LoadModule rewrite_module modules/mod_rewrite.so前面的#

二、在httpd.conf中查找以下部分:

<Directory />
 Options FollowSymLinks
 AllowOverride None
</Directory>

改为:

<Directory />
 Options FollowSymLinks
 AllowOverride All
</Directory>

三、重启apache服务器,添加.htaccess文件

RewriteEngine On
#以index.html代替index.php 
RewriteRule ^test.html$ test.php
#以test.php?id=2 伪静态 test_2.html
RewriteRule ^test_([0-9]{1,}).html$ test.php?id=$1