此篇为系列教程,为还在为dz伪静态烦恼的站长们助力(译版:为了申请版主而做准备)!
以discuz!3.2 + nginx为例!Apache,iis请自行转换!
【重要提醒:修改前请备份源文件,如果发现修改后进入页面空白,请检查代码是否修改正确!】
由于这个是把重要的代码全部【code】化,所以看起来会比较累!
所以提供百度文库及其豆丁版(都是本人上传,版主如果觉得有广告嫌疑请删除此段)
百度文库:http://wenku.baidu.com/view/2dd690381a37f111f0855b3e
豆丁:http://www.docin.com/p-1150307953.html
1、添加伪静态规则(以Nginx为例):
rewrite ^([^\.]*)/thread-([0-9]+)-f([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&fromuid=$3 last;
rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-u([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&authorid=$4&page=$3 last;
rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-o([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&ordertype=$4&page=$3 last;
rewrite ^([^\.]*)/thread-([1-9][0-9]*)-album\.html$ $1/forum.php?mod=viewthread&tid=$2&from=album last;
rewrite ^([^\.]*)/forum-([1-9][0-9]*)-last\.html$ $1/forum.php?mod=redirect&goto=nextoldset&tid=$2 last;
rewrite ^([^\.]*)/forum-([1-9][0-9]*)-next\.html$ $1/forum.php?mod=redirect&goto=nextnewset&tid=$2 last;
rewrite ^([^\.]*)/printable-([0-9]+)\.html$ $1/forum.php?mod=viewthread&action=printable&tid=$2 last;
依次为 复制链接、只看该作者、倒序看帖/正序看帖、只看大图、上一主题、下一主题、打印帖子 的伪静态规则。
2、修改“复制链接”的链接。打开 forum/viewthread.htm 模板文件,查找:
<a href="forum.php?mod=viewthread&tid=$_G[tid]$fromuid" {if $fromuid}title="{lang share_url_copy_comment}"{/if}>[{lang share_url_copy}]</a>
替换为:
<!--{if !IS_ROBOT}--><a href="thread-$_G[tid]-<!--{if $_G['uid']}-->f$_G['uid']<!--{else}-->1-1<!--{/if}-->.html" rel="nofollow" {if $fromuid}title="{lang share_url_copy_comment}"{/if}>[{lang share_url_copy}]</a><!--{/if}-->
3、修改楼层号上复制楼层地址的链接。打开 forum/viewthread_node.htm (或可能为viewthread_node_body.htm)模板文件,查找:
<a href="{if $post[first]}forum.php?mod=viewthread&tid=$_G[tid]$fromuid{else}forum.php?mod=redirect&goto=findpost&ptid=$_G[tid]&pid=$post[pid]$fromuid{/if}" {if $fromuid}title="{lang share_url_copy_comment}"{/if} id="postnum$post[pid]">
替换为:
<a href="{if $post[first]}forum.php?mod=viewthread&tid=$_G[tid]{else}thread-$_G[tid]-$page-1.html#pid$post[pid]{/if}" title="点此复制本帖链接" id="postnum$post[pid]">
4、“只看该作者”伪静态化。打开 forum/viewthread_node.htm (或可能为viewthread_node_body.htm)模板文件,查找:
<span class="pipe">|</span>
<!--{if !IS_ROBOT && !$_GET['authorid'] && !$_G['forum_thread']['archiveid']}-->
...
<!--{elseif !$_G['forum_thread']['archiveid']}-->
...
<!--{/if}-->
将整个if段替换为:
<!--{if !IS_ROBOT && !$_GET['authorid'] && !$_G['forum_thread']['archiveid']}-->
<span class="pipe">|</span>
<a href="thread-$post[tid]-1-u{$post[authorid]}.html" rel="nofollow">{lang thread_show_author}</a>
<!--{elseif !IS_ROBOT && !$_G['forum_thread']['archiveid']}-->
<span class="pipe">|</span>
<a href="forum.php?mod=viewthread&tid=$post[tid]&page=$page" rel="nofollow">{lang thread_show_all}</a>
<!--{/if}-->
5、“倒序/正序看帖”伪静态化。打开 forum/viewthread_node.htm (或可能为viewthread_node_body.htm)模板文件,查找:
<!--{if $ordertype != 1}-->
...
<!--{else}-->
...
<!--{/if}-->
将整个if段替换为:
<!--{if $ordertype != 1}-->
<span class="pipe show">|</span><a href="thread-$_G[tid]-1-o1.html" rel="nofollow" class="show">{lang post_descview}</a>
<!--{else}-->
<span class="pipe show">|</span><a href="thread-$_G[tid]-1-o2.html" rel="nofollow" class="show">{lang post_ascview}</a>
<!--{/if}-->
6、“只看大图”和“打印”“上一主题/下一主题”链接伪静态化。
打开 forum/viewthread_node.htm 模板文件,查找
<a href="forum.php?mod=viewthread&tid=$_G[tid]&from=album">{lang view_bigpic}</a>
替换为:
<a href="thread-$_G[tid]-album.html" rel="nofollow"><font color="#336699">相册模式</a>
打开 forum/viewthread.htm 模板文件,查找:
forum.php?mod=viewthread&action=printable&tid=$_G[tid]
替换为:
printable-$_G[tid].html
查找:
forum.php?mod=redirect&goto=nextoldset&tid=$_G[tid]
替换为:
thread-$_G[tid]-prev.html
超找:
forum.php?mod=redirect&goto=nextnewset&tid=$_G[tid]
替换为:
thread-$_G[tid]-next.html
打开 source/module/forum/forum_redirect.php 文件,将:
if($next) {
dheader("Location: forum.php?mod=viewthread&tid=$next");
} elseif($_GET['goto'] == 'nextnewset') {
showmessage('redirect_nextnewset_nonexistence');
} else {
showmessage('redirect_nextoldset_nonexistence');
}
替换为:
if($next) {
dheader("Location: thread-$next-1-1.html");
} elseif($_GET['goto'] == 'nextnewset') {
header('HTTP/1.1 404 Not Found');
showmessage('redirect_nextnewset_nonexistence');
} else {
header('HTTP/1.1 404 Not Found');
showmessage('redirect_nextoldset_nonexistence');
}
7、帖子内容页翻页按钮伪静态化。
打开 source/module/forum/forum_viewthread.php 文件,查找:
} else {
$_GET['viewpid'] = intval($_GET['viewpid']);
在它上面加入:
$multipage_thread = multi_thread($_G['forum_thread']['replies'] + 1, $_G['ppp'], $page, 'thread-'.$_G['tid']);
打开 source/function/function_core 文件,
在
function simplepage($num, $perpage, $curpage, $mpurl) {
前面增加一段(定义multi_thread):
function multi_thread($num, $perpage, $curpage, $mpurl, $maxpages = 0, $page = 10, $autogoto = FALSE, $simple = FALSE, $jsfunc = FALSE) {
return $num > $perpage ? helper_page_thread::multi($num, $perpage, $curpage, $mpurl, $maxpages, $page, $autogoto, $simple, $jsfunc) : '';
}
进入 source/class/helper/ 目录,将 helper_page.php 复制一份命名为 helper_page_thread.php 。并依次修改 helper_page_thread.php 文件中的以下部分:
将
helper_page
修改为
helper_page_thread
(共两处,其中文件头注释中的那处无关紧要);
将
$pagevar = 'page=';
修改为
$pagevar = '-';
在
$wml = defined('IN_MOBILE') && IN_MOBILE == 3;
前面新增:
[code]if($_GET['authorid']) {
$url_filter = '-u'.$_GET['authorid'];
} elseif($_GET['ordertype'] == 1 || $_GET['ordertype'] == 2) {
$url_filter = '-o'.$_GET['ordertype'];
} else {
$url_filter = '-1';
}
将
$jsurl = $mpurl.(strpos($mpurl, '{page}') !== false ? '\'.replace(\'{page}\', this.value == 1 ? \'\' : this.value)': $pagevar.'\'+this.value;').'; doane(event);';
替换为:
$jsurl = substr($mpurl, 0, -1).(strpos($mpurl, '{page}') !== false ? '\'.replace(\'{page}\', this.value == 1 ? \'\' : this.value)': $pagevar.'\'+this.value').'+\''.$url_filter.'.html\'; doane(event);';
在
[code]public static function mpurl($mpurl, $pagevar, $page) {[/code]
下新增:
[code]if($_GET['authorid']) {
$url_filter = '-u'.$_GET['authorid'];
} elseif($_GET['ordertype'] == 1 || $_GET['ordertype'] == 2) {
$url_filter = '-o'.$_GET['ordertype'];
} else {
$url_filter = '-1';
}[/code]
将
[code]return $mpurl.$separator.$pagevar.$page;[/code]
替换为:
[code]return substr($mpurl, 0, -1).$separator.$pagevar.$page.$url_filter.'.html';[/code]
打开 forum/viewthread.htm 模板文件,查找:
[code]<div class="pgt">$multipage</div>[/code]
替换为
[code]<div class="pgt"><!--{if $_GET['highlight'] || $_GET['modthreadkey'] || $_GET['checkrush'] || $_G['forum_thread']['is_archived']}-->$multipage<!--{else}-->$multipage_thread<!--{/if}--></div>[/code]
查找:
[code]<div class="pgs mtm mbm cl">[/code]
将其下方的
[code]$multipage[/code]
的替换为:
[code]<!--{if $_GET['highlight'] || $_GET['modthreadkey'] || $_GET['checkrush'] || $_G['forum_thread']['is_archived']}-->$multipage<!--{else}-->$multipage_thread<!--{/if}-->[/code]
8、“电梯直达”伪静态。
打开 forum/viewthread_node.htm 模板文件(有可能在 viewthread_node_body.htm 中),
查找:
[code]<label class="z">{lang thread_redirect_postno}</label>
<input type="text" class="px p_fre z" size="2" title="{lang thread_redirect_postno_tips}" />[/code]
替换为:
[code]<label class="z">楼层跳转</label>
<input type="text" class="px p_fre z" size="2" title="{lang thread_redirect_postno_tips}" />[/code]
打开 source/module/forum/forum_redirect.php 文件,查找:
[code]header("HTTP/1.1 301 Moved Permanently");
dheader("Location: forum.php?mod=viewthread&tid=$tid&page=$page$authoridurl$ordertypeurl".(isset($_GET['modthreadkey']) && ($modthreadkey = modauthkey($tid)) ? "&modthreadkey=$modthreadkey": '')."#pid$pid");[/code]
替换为:
[code]$authoridurl2 = $authorid ? 'u'.$authorid : '';
$ordertypeurl2 = $ordertype ? 'o'.$ordertype : '';
if(!$authorid && !$ordertype) {
$noother = '1';
}
header("HTTP/1.1 301 Moved Permanently");
if(!$modthreadkey) {
dheader("Location: thread-$tid-$page-".$authoridurl2.$ordertypeurl2.$noother.".html#pid$pid");
} else {
dheader("Location: forum.php?mod=viewthread&tid=$tid&page=$page$authoridurl$ordertypeurl".(isset($_GET['modthreadkey']) && ($modthreadkey = modauthkey($tid)) ? "&modthreadkey=$modthreadkey": '')."#pid$pid");
}[/code]
查找:
[code]if($ptid) {
header("HTTP/1.1 301 Moved Permanently");
dheader("Location: forum.php?mod=viewthread&tid=$ptid");[/code]
替换为:
[code]$authoridurl3 = $authorid ? 'u'.$authorid : '';
$ordertypeurl3 = $ordertype ? 'o'.$ordertype : '';
if(!$authorid && !$ordertype) {
$noother = '1';
}
if($ptid) {
header("HTTP/1.1 301 Moved Permanently");
dheader("Location: thread-$ptid-1-".$authoridurl3.$ordertypeurl3.$noother.".html");[/code]
9、最后,在根目录 robots.txt 文件中添加:
[code]Disallow: /printable-*.html
Disallow: /thread-*f*.html
Disallow: /thread-*o*.html
Disallow: /thread-*u*.html
Disallow: /thread-*album.html
Disallow: /thread-*prev.html
Disallow: /thread-*next.html[/code]
【discuz伪静态】系列之一:http://bbs.aliyun.com/read/244384.html
【discuz伪静态】系列之二:http://bbs.aliyun.com/read/244388.html
【discuz伪静态】系列之三:
http://bbs.aliyun.com/read/244531.html
【discuz伪静态】系列之四:http://bbs.aliyun.com/read/244529.html
【discuz伪静态】系列之五(附件篇):
rewrite ^([^\.]*)/thread-([0-9]+)-f([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&fromuid=$3 last;
rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-u([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&authorid=$4&page=$3 last;
rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-o([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&ordertype=$4&page=$3 last;
rewrite ^([^\.]*)/thread-([1-9][0-9]*)-album\.html$ $1/forum.php?mod=viewthread&tid=$2&from=album last;
rewrite ^([^\.]*)/forum-([1-9][0-9]*)-last\.html$ $1/forum.php?mod=redirect&goto=nextoldset&tid=$2 last;
rewrite ^([^\.]*)/forum-([1-9][0-9]*)-next\.html$ $1/forum.php?mod=redirect&goto=nextnewset&tid=$2 last;
rewrite ^([^\.]*)/printable-([0-9]+)\.html$ $1/forum.php?mod=viewthread&action=printable&tid=$2 last;
RewriteEngine On
RewriteBase /
RewriteRule ^([^.]*)/thread-([0-9]+)-f([0-9]+).html$ $1/forum.php?mod=viewthread&tid=$2&fromuid=$3 [L]
RewriteRule ^([^.]*)/thread-([0-9]+)-([0-9]+)-u([0-9]+).html$ $1/forum.php?mod=viewthread&tid=$2&authorid=$4&page=$3 [L]
RewriteRule ^([^.]*)/thread-([0-9]+)-([0-9]+)-o([0-9]+).html$ $1/forum.php?mod=viewthread&tid=$2&ordertype=$4&page=$3 [L]
RewriteRule ^([^.]*)/thread-([1-9][0-9]*)-album.html$ $1/forum.php?mod=viewthread&tid=$2&from=album [L]
RewriteRule ^([^.]*)/forum-([1-9][0-9]*)-last.html$ $1/forum.php?mod=redirect&goto=nextoldset&tid=$2 [L]
RewriteRule ^([^.]*)/forum-([1-9][0-9]*)-next.html$ $1/forum.php?mod=redirect&goto=nextnewset&tid=$2 [L]
RewriteRule ^([^.]*)/printable-([0-9]+).html$ $1/forum.php?mod=viewthread&action=printable&tid=$2 [L]
-------------------------
-------------------------
-------------------------
-------------------------
-------------------------
-------------------------
-------------------------
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。