七分地
soncy的七分责任田,种点瓜果蔬菜和杂草
discuz的一些URL静态化备忘
发表于 2009年09月6日
1,134次阅读
捣鼓第八站论坛的时候想到要把论坛做成url静态化的,于是查了点资料,存下以备不时之需。只记录用apche作服务器的情况。
一,URL的静态化可以在后台开启,官方有帮助文档,在后台开启后,改写.htaccess
在开始以下设置之前,请首先咨询您的空间服务商,空间是否支持 Rewrite 以及是否支持对站点目录中 .htaccess 的文件解析,否则即便按照下面的方法设置好了,也无法使用。
检查论坛所在目录中是否存在 .htaccess 文件,如果不存在,请手工建立此文件。Win32 系统下,无法直接建立 .htaccess 文件,您可以从其他系统中拷贝一份,或者在 Discuz.net 技术支持栏目中下载此文件。编辑并修改 .htaccess 文件,添加以下内容
- # 将 RewriteEngine 模式打开
- RewriteEngine On
- # 修改以下语句中的 /discuz 为你的论坛目录地址,如果程序放在根目录中,请将 /discuz 修改为 /
- RewriteBase /discuz
- # Rewrite 系统规则请勿修改
- RewriteRule ^archiver/((fid|tid)-[\w\-]+\.html)$ archiver/index.php?$1
- RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2
- RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ viewthread.php?tid=$1&extra=page\%3D$3&page=$2
- RewriteRule ^space-(username|uid)-(.+)\.html$ space.php?$1=$2
- RewriteRule ^tag-(.+)\.html$ tag.php?name=$1
二,从论坛其他页面回到首页的时候链接是http://bbsurl/index.php,可以在论坛后台设置首页文件名为index.html或者干脆设置成/。然后必须做的意见事情是让首页伪静态了。
打开 .htaccess 文件, 查找:
- RewriteRule ^space-(username|uid)-(.+)\.html$ space.php?$1=$2
在下面添加:
- RewriteRule ^index\.html$ index.php
- RewriteRule ^index-([0-9]+)\.html$ index.php?gid=$1
打开后台, 关闭静态化 URL 的功能.
打开 include/global.func.php 文件, 查找:
if($rewritestatus & 1)上面添加
$indexhtml = 1; //1开启首页静态化,0关闭首页静态化 $gidhtml = 1; //1开启首页静态化,0关闭首页静态化 if($indexhtml == 1) { $searcharray[] = "/\<a href\=\"index\.php\"([^\>]*)\>/e"; $replacearray[] = "rewrite_index('\\1')"; } if($gidhtml == 1) { $searcharray[] = "/\<a href\=\"index\.php\?gid\=(\d+)\"([^\>]*)\>/e"; $replacearray[] = "rewrite_index('\\2', '\\1')"; }再找:
function rewrite_thread($tid, $page = 0, $prevpage = 0, $extra = '')上面添加:
function rewrite_index($extra = '', $gid = 0) { return '<a href="index'.($gid ? '-'.$gid : '').'.html"'.stripslashes($extra).'>'; }
三,首页最后发表/最后回复的URL静态化
打开模板文件discuz.htm,查找
redirect.php?tid=$forum[lastpost][tid]&goto=lastpost#lastpost全部替换:
thread-$forum[lastpost][tid]-1-1.html
完了,效果可见 http://bbs.dibazhan.cn
感谢您的浏览,如果您喜欢本站,可以通过Rss订阅本站,如需转载,请注明出处,谢谢!
发表评论

用老兄的名字来形容最近的Google PR更新可谓强大。
[回复]