赢在执行

这个世界上只有两样东西愈分享愈多,那就是智慧与爱。

BlogJava 首页 新随笔 联系 聚合 管理
  17 Posts :: 11 Stories :: 13 Comments :: 0 Trackbacks
关于Apache实现UrlRewrite静态化页面的配置
2007年07月27日 星期五 22:56

关于UrlRewrite静态化的说明:

(1)apache用户,首先确认您的服务器是apache架设的web服务器(此插件只使用于apache架设的服务器)
Apache Web Server(独立主机用户)
首先确定您使用的 Apache 版本,及是否加载了 mod_rewrite 模块。
Apache 1.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 ^(.*)/forum-([0-9]+)-([0-9]+)-([0-9]+).html[?]{0,1}(.*)$ $1/forumdisplay.php
            ?f=$2&st=$4&pp=$3&$5
            RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+).html[?]{0,1}(.*)$ $1/forumdisplay.php?f=$2&pp=$3&$4
            RewriteRule ^(.*)/forum-([0-9]+)-(q?)-([0-9]+).html[?]{0,1}(.*)$ $1/forumdisplay.php
            ?f=$2&filter=quintessence&pp=$3&$4
            RewriteRule ^(.*)/forum-([0-9]+)-(q?).html[?]{0,1}(.*)$ $1/forumdisplay.php
            ?f=$2&filter=quintessence&$4
            RewriteRule ^(.*)/forum-([0-9]+).html[?]{0,1}(.*)$ $1/forumdisplay.php?f=$2&$3
            RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+).html[?]{0,1}(.*)$ $1/showthread.php?t=$2&pp=$3&$4
            RewriteRule ^(.*)/thread-([0-9]+).html[?]{0,1}(.*)$ $1/showthread.php?t=$2&$3
            RewriteRule ^(.*)/user-([0-9]+).html $1/profile.php?u=$2[L]
            RewriteRule ^(.*)/archive/f-([0-9]+)-([0-9]+).html $1/index.php?f$2-$3.html[L]
            RewriteRule ^(.*)/archive/t-([0-9]+)-([0-9]+).html $1/index.php?t$2-$3.html[L]
            </IfModule>
            如果没有安装 mod_rewrite,您可以重新编译 Apache,并在原有 configure 的内容中加入
            --enable-rewrite=shared,然后再在 Apache 配置文件中加入上述代码即可。 
Apache Web Server(虚拟主机用户)
在开始以下设置之前,请首先咨询您的空间服务商,空间是否支持 Rewrite 以及是否支持对站点
            目录中 .htaccess 的文件解析,否则即便按照下面的方法设置好了,也无法使用。
            
检查论坛所在目录中是否存在 .htaccess 文件,如果不存在,请手工建立此文件。Win32 系统下
            ,无法直接建立 .htaccess 文件,您可以从其他系统中拷贝一份,或者在 魔力论坛技术支持栏目
            中下载此文件。编辑并修改 .htaccess 文件,添加以下内容 :
            
# 将 RewriteEngine 模式打开
            RewriteEngine On
            
# 修改以下语句中的 /molyx_board 为你的论坛目录地址,如果程序放在根目录中,请将
            /molyx_board 修改为 /
            RewriteBase /molyx_board/
            # Rewrite 系统规则请勿修改
            RewriteRule forum-([0-9]+)-([0-9]+)-([0-9]+).html forumdisplay.php?f=$1&st=$3&pp=$2&$4
            RewriteRule forum-([0-9]+)-([0-9]+).html forumdisplay.php?f=$1&pp=$2&$3
            RewriteRule forum-([0-9]+)-(q?)-([0-9]+).html forumdisplay.php?f=$1&filter=quintessence&pp=$3
            RewriteRule forum-([0-9]+)-(q?).html forumdisplay.php?f=$1&filter=quintessence
            RewriteRule forum-([0-9]+).html forumdisplay.php?f=$1
            RewriteRule thread-([0-9]+)-([0-9]+).html showthread.php?t=$1&pp=$2&$3
            RewriteRule thread-([0-9]+).html showthread.php?t=$1&$2
            RewriteRule user-([0-9]+).html profile.php?u=$1
            RewriteRule archive/f-([0-9]+)-([0-9]+).html archive/index.php?f$1-$2.html
            RewriteRule archive/t-([0-9]+)-([0-9]+).html archive/index.php?t$1-$2.html
 
以上为开启URL静态化的整个说明。
本人是独立主机,按照上面做,一直没有成功。开启静态化后,提示
            

The requested URL thread-11955.html was not found on this server

困惑了一天,修改了很多次规则都不行。后来尝试着结合虚拟主机用户方法。首先把httpd.conf中的规则

配置去掉,然后在论坛根目录创建.htaccess 文件,然后把规则写进去,重启apache,一切OK啦。

规则如下:

<IfModule mod_rewrite.c>

# 将 RewriteEngine 模式打开
            RewriteEngine On
            
# 修改以下语句中的 /molyx_board 为你的论坛目录地址,如果程序放在根目录中,请将
            /molyx_board 修改为 /
            RewriteBase /molyx_board/
            # Rewrite 系统规则请勿修改
            RewriteRule forum-([0-9]+)-([0-9]+)-([0-9]+).html forumdisplay.php?f=$1&st=$3&pp=$2&$4
            RewriteRule forum-([0-9]+)-([0-9]+).html forumdisplay.php?f=$1&pp=$2&$3
            RewriteRule forum-([0-9]+)-(q?)-([0-9]+).html forumdisplay.php?f=$1&filter=quintessence&pp=$3
            RewriteRule forum-([0-9]+)-(q?).html forumdisplay.php?f=$1&filter=quintessence
            RewriteRule forum-([0-9]+).html forumdisplay.php?f=$1
            RewriteRule thread-([0-9]+)-([0-9]+).html showthread.php?t=$1&pp=$2&$3
            RewriteRule thread-([0-9]+).html showthread.php?t=$1&$2
            RewriteRule user-([0-9]+).html profile.php?u=$1
            RewriteRule archive/f-([0-9]+)-([0-9]+).html archive/index.php?f$1-$2.html
            RewriteRule archive/t-([0-9]+)-([0-9]+).html archive/index.php?t$1-$2.html

</IfModule>

posted on 2008-02-01 00:40 飛雪(leo) 阅读(3588) 评论(0)  编辑  收藏 所属分类: 个人日记

只有注册用户登录后才能发表评论。


网站导航: