Apache环境下Discuz论坛url_rewrite配置

Apache环境下DZ论坛url_rewrite配置
url_rewrite有什么好处?
当然有,输出.html格式有利于搜索引擎收录。
我今天才开始弄,在网上找了相关资料,没找到,经童虎指点
在几次修改、测试的情况下终于成功
演示:(暂无)
首页:http://www.todayit.com.cn/index.html
其他还有很多,大家可以随意设置哪个动态页url_rewrite
首先你的服务器得支持url_rewrite和.htaccess,否则请按照如下设置

一、设置httpd.conf文件
1、删除以下两行前的注释#

QUOTE:
LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c

2、使APACHE支持.htaccess

QUOTE:
<Directory “g:/wwwroot”>

#
# This may also be “None”, “All”, or any combination of “Indexes”,
# “Includes”, “FollowSymLinks”, “ExecCGI”, or “MultiViews”.
#
# Note that “MultiViews” must be named *explicitly* — “Options All”
# doesn’t give it to you.
#
Options Indexes FollowSymLinks MultiViews

#
# This controls which options the .htaccess files in directories can
# override. Can also be “All”, or any combination of “Options”, “FileInfo”,
# “AuthConfig”, and “Limit”
#
AllowOverride All 将none改成ALL
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
我的.htaccess文件如下:

CODE:[Copy to clipboard]RewriteEngine On
RewriteBase /
RewriteRule ^archiver/([a-z0-9-]+.html)$ $1/archiver/index.php?$2
RewriteRule ^index.html$ $1/index.php?sid=$2
RewriteRule ^(.*)digest.html$ $1/digest.php
RewriteRule ^(.*)thread-([0-9]+).html$ $1/viewthread.php?tid=$2
RewriteRule ^(.*)forum-([0-9]+).html$ $1/forumdisplay.php?fid=$2
RewriteRule ^(.*)forum-([0-9]+).html$ $1/forumdisplay.php?fid=$fup[fid]
RewriteRule ^(.*)thread-([0-9]+)-([0-9]+).html$ $1/viewthread.php?tid=$2&page=$3&fpage=$4
RewriteRule ^(.*)forum-([0-9]+)-([0-9]+).html$ $1/forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)forum-([0-9]+)-([a-z0-9-]+).html$ $1/forumdisplay.php?fid=$2&filter=$3
RewriteRule ^(.*)thread-([0-9]+)-([0-9]+).html$ $1/viewthread.php?fid=$2&tid=$3&action=printable

目前我只设置这么多,大家需要可以自己设置
RewriteBase /为目录,如果是/bbs则设置为RewriteBase /bbs
RewriteRule ^index.html$ $1/index.php?sid=$2
这样用户访问index.html时就映射到了index.php上
同样
RewriteRule ^(.*)forum-([0-9]+).html$ $1/forumdisplay.php?fid=$2
当用户访问forum-数字.html时候就映射到了forumdisplay.php?fid=$2
其中$2为传递版面ID变量

这样做好了模板还需要做相应修改,比如forum-1.html可以访问$fd=1的版面,那么我们将相应的forumdisplay.php?fid=$fid连接改为forum-$fid.html就可以了

其实很简单,甚至可以将所有页面url_rewrite化,不过我只做这几个页。主要是为了收录帖子。其他还是动态页。大家可以参考以上代码url_rewrite其他页面。

最后记得.htaccess文件2进制上传,属性644

===================================
Zeus规则
DZ参考

CODE:[Copy to clipboard]match URL into $ with ^(.*)/archiver/([a-z0-9-]+.html)$
if matched then
set URL = $1/archiver/index.php?$2
endif

match URL into $ with ^(.*)/forum-([0-9]+)-([0-9]+).html$
if matched then
set URL = $1/forumdisplay.php?fid=$2&page=$3
endif

match URL into $ with ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$
if matched then
set URL = $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3
endif

match URL into $ with ^(.*)/profile-(username|uid)-(.+?).html$
if matched then
set URL = $1/viewpro.php?$2=$3
endif
有关url_rewrite更多资料:http://www.discuz.net/viewthread.php?tid=208240

相关文章

发表评论

返回顶部