java urlrewrite 配置_关于Apache实现UrlRewrite静态化页面的配置

本文档详细介绍了如何在Apache服务器上配置URL重写规则,以实现URL静态化。对于独立主机用户,步骤包括重新编译Apache、添加配置选项、创建.htaccess文件并添加规则。在遇到开启URL静态化失败的问题时,作者通过移除httpd.conf中的规则,将规则写入.htaccess文件并重启Apache,最终解决了问题。这是一个关于Apache Rewrite规则配置和问题排查的实例。
摘要由CSDN通过智能技术生成

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]

如果没有安装 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啦。

规则如下:

# 将 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值