为了方便省事,默认使用phpstudy这个套件来运行php程序,但是发现phpstudy下好像无法使用伪静态,windows下似乎是不支持.htaccess文件的,所以要写到httpd.ini文件里,经过如下设置试验成功。
一 开启Mod_rewrite模块
点击任务栏中的phpstyudy图标,选择“配置文件”--“httpd-conf”
搜索 LoadModule rewrite_module modules/mod_rewrite.so (Apache2是这个)
去掉前面的#
搜索AllowOverride None 替换为 AllowOverride All
有好几个找到和下面代码类似的那个
#
# "D:\usr\local\Apache2\cgi-bin" should be changed to whatever your scriptAliased
# CGI directory exists, if you have that configured.
#
AllowOverride All
Options None
Order allow,deny
Allow from all
二 在Apache2\conf\httpd.conf 最后一行添加: (这个是关键点) 这是写好的DT规则可以直接使用(也可以自己添加)
<IfModule mod_rewrite.c>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)\.(asp|aspx|asa|asax|dll|jsp|cgi|fcgi|pl)(.*)$ /404.php
RewriteRule ^(.*)/(admin|cache|editor|file|include|lang|module|skin|template)/(.*)\.php(.*)$ /404.php
RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
RewriteRule ^(.*)/show-([0-9]+)([\-])?([0-9]+)?\.html$ $1/show.php?itemid=$2&page=$4
RewriteRule ^(.*)/list-([0-9]+)([\-])?([0-9]+)?\.html$ $1/list.php?catid=$2&page=$4
RewriteRule ^(.*)/([A-za-z0-9_\-]+)-c([0-9]+)-([0-9]+)\.html$ $1/list.php?catid=$3&catdir=$2&page=$4
RewriteRule ^(.*)/show/([0-9]+)/([0-9]+)?([/])?$ $1/show.php?itemid=$2&page=$3
RewriteRule ^(.*)/list/([0-9]+)/([0-9]+)?([/])?$ $1/list.php?catid=$2&page=$3
RewriteRule ^(.*)/([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/index.php?moduleid=$2&catid=$3&itemid=$4&page=$5
RewriteRule ^(.*)/([a-z]+)/(.*)\.shtml$ $1/$2/index.php?rewrite=$3
RewriteRule ^(com)/([a-z0-9_\-]+)/([a-z]+)/(.*)\.html$ index.php?homepage=$2&file=$3&rewrite=$4
RewriteRule ^(com)/([a-z0-9_\-]+)/([a-z]+)([/])?$ index.php?homepage=$2&file=$3
RewriteRule ^(com)/([a-z0-9_\-]+)([/])?$ index.php?homepage=$2
</IfModule>
然后重新Apache后就可以正常使用了。