自己动手简单实现vbb的URL静态化

只要作简单的修改,就能实现vbb的URL静态化,当然,需要服务器支持rewrite功能。
使用的论坛版本为vbulletin v3.6.8英文标准版。
-------------------------第一步---------------------------
-------------------------------------------------
在includes/functions.php中找到:
------------------------------------------------

PHP 代码:
 
 
 
  1. function print_output($vartext$sendheader = true) 
  2.     global $pagestarttime$querytime$vbulletin
  3.     global $vbphrase$stylevar
  4.  
  5.     if ($vbulletin->options['addtemplatename']) 
  6.     {   

----------------------------------------------------------
改为:
---------------------------------------------------------

PHP 代码:
 
 
  1. //######################################### 
  2. //增加两个 Function 开始 
  3. function rewrite_forum($extra1$sid$fid$order$page = 0, $extra2 = ''
  4.     return '<a ' . stripslashes($extra1) . ' href="f-' . ($sid ? substr($sid, 0, 32) : 0) . '-' . $fid . '-' . ($order ? $order : 0) . '-' . ($page ? $page : 1) . '.html"'.stripslashes($extra2).'>'
  5. function rewrite_thread($extra1$sid$tid$page = 0, $extra2 = ''
  6.  { 
  7.     return '<a ' . stripslashes($extra1) . ' href="t-' . ($sid ? substr($sid, 0, 32) : 0) . '-' . $tid . '-' . ($page ? $page : 1) . '.html"'.stripslashes($extra2).'>'
  8. //增加两个 Function 结束 
  9. //######################################### 
  10. function print_output($vartext$sendheader = true) 
  11.     global $pagestarttime$querytime$vbulletin
  12.     global $vbphrase$stylevar
  13. //######################################### 
  14. //增加程序开始 
  15.     $searcharray[] = "/\<a(.*)href\=\"forumdisplay\.php\?(s\=(.*))?f\=(\d+)(&amp;order\=(asc|desc))?(&amp;page\=(\d+))?\"([^\>]*)\>/e"
  16.     $replacearray[] = "rewrite_forum('\\1', '\\3','\\4', '\\6', '\\8','\\9')"
  17.  
  18.     $searcharray[] = "/\<a(.*)href\=\"showthread\.php\?(s\=(.*))?t\=(\d+)(&amp;page\=(\d+))?\"([^\>]*)\>/e"
  19.     $replacearray[] = "rewrite_thread('\\1', '\\3','\\4', '\\6', '\\7')";     
  20.      
  21.     $vartext = preg_replace($searcharray$replacearray$vartext); 
  22. //增加程序结束 
  23. //######################################### 
  24.     if ($vbulletin->options['addtemplatename']) 
  25.     {   

-------------------------------------------------


 

如果你想同时重写archive,请作如下修改:


 

------------------------------------------------


 

在archive/index.php中找到如下语句:


 

--------------------------------------------


 

PHP 代码:
 
 
  1. if (SLASH_METHOD AND strpos($archive_info , '/archive/index.php/') === false) 
  2.     exec_header_redirect($vbulletin->options['bburl'] . '/archive/index.php/'); 
  3. }   

-----------------------------
改为
----------------------------------------------------------

PHP 代码:
 
 
  1. if (SLASH_METHOD AND strpos($archive_info , '/archive/') === false) 
  2.     exec_header_redirect($vbulletin->options['bburl'] . '/archive/'); 
  3. }   

-------------------------第二步---------------------------
-----------------------------------------------------
在论坛的根目录下增加文件".htaccess",文件中包含如下内容:
-----------------------------------------------------

代码:
 
 
 
  1. RewriteEngine On 
  2. # 修改"/vbb"为你的论坛目录地址,如果程序放在根目录中,请将 "/vbb"修改为" /" 
  3. RewriteBase /vbb 
  4. RewriteRule ^f-([0-9a-z]+)-([0-9]+)-(0|asc|desc)-([0-9]+)\.html$ forumdisplay.php?s=$1&f=$2&order=$3&page=$4 
  5. RewriteRule ^t-([0-9a-z]+)-([0-9]+)-([0-9]+)\.html$ showthread.php?s=$1&t=$2&page=$3 
  6. RewriteRule ^archive/((f|t)-[0-9]+\.html)$ archive/index.php?$1 

---------------------------------------------------
已知Bug,
在forumdisplay.php的分主题分页菜单处;
在forumdisplay.php的主题列表的快速分页链接处;
在showthread.php的主题分页菜单处;
部分动态页没有重写过来,但不影响实际使用。
对archive的重写,没有发现不正常。
如果你对这个Bug介意的话,你可以只选择重写archive,这样你所要修改的仅仅是对archive/index.php中的一点点的修改(方法同 上),而不必修改includes/functions.php文件,并把".htaccess"文件放入archive文件夹中,然后在 ".htaccess"中只保留:
-----------------------------------------------------

代码:
 
 
  1. RewriteEngine On 
  2. # 修改"/vbb"为你的论坛目录地址,如果程序放在根目录中,请将 "/vbb"修改为" /archive" 
  3. RewriteBase /vbb/archive 
  4. RewriteRule ^((f|t)-[0-9]+\.html)$ index.php?$1 

---------------------------------------------------
这样你在打开archive功能的情况下还是可以为你的论坛提高搜索引擎的搜索效果的。
-------------------------------------------------
很明显我的改法太没水平了,因为这是我第一次写rewrite的,我对正规表达式也是一知半解。不过我对VBB的代码倒是十分的了解,觉得VBB的编程风格还不错,用来学习PHP4,是一个不错的选择,不过要学PHP5的话,看WBB3的代码绝对是首选。
本来打算把VBB的URL重写进一步完善,写成一个VBB插件,并增加后台的开关功能(setting)的,不过学校开学了,我上大四了,想再过一次独木桥,比较忙,而且网线过几天就到期了,不想续了,租个房子,闭关半年,所以,就不写了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值