如何实现apache的rewrite伪静态
首先确定您使用的 Apache版本,及是否加载了mod_rewrite模块。
Apache1.x的用户请检查conf/httpd.conf中是否存在如下两段代码:
LoadModule rewrite_module libexec/mod_rewrite.so
AddModule mod_rewrite.c
Apache 2.x 的用户请检查 conf/httpd.conf 中是否存在如下一段代码:
LoadModule rewrite_module modules/mod_rewrite.so
如果存在,那么在配置文件(通常就是 conf/httpd.conf)中加入如下代码。此时请务必注意,如果网站使用通过虚拟主机来定义,请务必加到虚拟主机配置,即 <VirtualHost> 中去,如果加在虚拟主机配置外部将可能无法使用。改好后然后将 Apache 重启。
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2 RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3 RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3 RewriteRule ^(.*)/space-(username|uid)-(.+)\.html$ $1/space.php?$2=$3 RewriteRule ^(.*)/tag-(.+)\.html$ $1/tag.php?name=$2 </IfModule>
如果没有安装 mod_rewrite,您可以重新编译 Apache,并在原有configure的内容中加入–enable-rewrite=shared,然后再在 Apache 配置文件中加入上述代码即可。


评论
还没有评论。
发表评论