打印

[安装使用] 自己改造客客系统的伪静态,让伪静态更友好更好看(20120506更新)

  [复制链接]
查看: 7097   回复: 22
跳转到指定楼层
1
MCCAD 发表于 2012-5-4 15:19:25 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 MCCAD 于 2012-5-6 18:20 编辑

第一眼看到客客的伪静态格式就被雷倒了。简直不是人写的, 是神写的,因为跟看天书一样,又臭又长。我也提过意见给官方,但估计官方是很难接受的,因为他们的思维模式已经定了,他们觉得挺好,那只能自己动手了。
一、找到\lib\inc\keke_tpl_class.php大约190行左右:

  1. if ($_K ['is_rewrite'] == 1) {
  2. $preg_searchs [] = "/\<a href\=\"index\.php\?(.+?)\#(\w+)\"/ie";
  3. $preg_searchs [] = "/\<a href\=\"index\.php\"/i";
  4. $preg_searchs [] = "/\<a href\=\"http\:\/\/(.*)\/index\.php\?(.+?)\#(\w+)\"/ie";
  5. $preg_searchs [] = "/\<a href\=\"index\.php\?(.+?)\"/ie";
  6. $preg_replaces [] = 'keke_tpl_class::rewrite_url(\'index-\',\'\\1\',\'\\2\')';
  7. $preg_replaces [] = '<a href="index.html"';
  8. $preg_replaces [] = 'keke_tpl_class::rewrite_url(\'http://\\1/index-\',\'\\2\',\'\\3\')';
  9. $preg_replaces [] = 'keke_tpl_class::rewrite_url(\'index-\',\'\\1\')';
  10. }
复制代码

改成
  1. if ($_K ['is_rewrite'] == 1) {
  2. $preg_searchs [] = "/\<a href\=\"(http\:\/\/.*\/|)(index\.php\?do\=)article\&view\=(article_info|article_index|article_list)/";
  3. $preg_replaces [] = '<a href="\\1\\2\\3';

  4. $preg_searchs [] = "/\<a href\=\"(http\:\/\/.*\/|)index\.php\?do\=article_list\&year=(\d+)(\#\w+|)\"/";
  5. $preg_replaces [] = '<a href="\\1article_year-\\2.html\\3"';

  6. $preg_searchs [] = "/\<a href\=\"(http\:\/\/.*\/|)index\.php\?do\=(task_list|shop_list|task|service|help|article_info|article)\&(path|task_id|sid|fpid|art_cat_id|page_size1)\=(\w*)\&(indus_id|view|spid|art_id|page)\=(\w+)(\#\w+|)\"/";
  7. $preg_replaces [] = '<a href="\\1\\2-\\4-\\6.html\\7"';

  8. $preg_searchs [] = "/\<a href\=\"(http\:\/\/.*\/|)index\.php\?do\=(task|service|space|task_list|shop_list|shop|help|article_list|article_info)\&(task_id|sid|member_id|path|fpid|art_cat_id|art_id)\=(\w+)(\#\w+|)\"/";
  9. $preg_replaces [] = '<a href="\\1\\2-\\4.html\\5"';

  10. $preg_searchs [] = "/\<a href\=\"(http\:\/\/.*\/|)index\.php\?do\=(task|shop|case|article|task_list|task_map|shop_list|shop_map|release|shop_release|help|login|link|)(_index|)(\#\w+|)\"/";
  11. $preg_replaces [] = '<a href="\\1\\2.html\\4"';

  12. $preg_searchs [] = "/\<a href\=\"(http\:\/\/.*\/|)index\.php(\#\w+|)\"/i";
  13. $preg_replaces [] = '<a href="\\1index.html\\2"';
  14. }
复制代码

二、伪静态的规则:
如果是IIS的.htaccess
  1. # Rewrite 系统规则请勿修改
  2. RewriteRule index\.html /index.php [N,I]

  3. RewriteRule task-([0-9]+)\.html /index.php\?do=task&task_id=$1 [N,I]
  4. RewriteRule service-([0-9]+)\.html /index.php\?do=service&sid=$1 [N,I]
  5. RewriteRule space-([0-9]+)\.html /index.php\?do=space&member_id=$1 [N,I]
  6. RewriteRule help-([0-9]+)\.html /index.php\?do=help&fpid=$1 [N,I]
  7. RewriteRule article_list-([0-9]+)\.html /index.php\?do=article&view=article_list&art_cat_id=$1 [N,I]
  8. RewriteRule article_year-([0-9]+)\.html /index.php\?do=article&view=article_list&year=$1 [N,I]
  9. RewriteRule (task_list|shop_list|shop)-(\w+)\.html /index.php\?do=$1&path=$2 [N,I]
  10. RewriteRule article_info-(\w+)\.html /index.php\?do=article&view=article_info&art_id=$1 [N,I]

  11. RewriteRule (task_list|shop_list)-(\w*)-(\w+)\.html /index.php\?do=$1&path=$2&indus_id=$3 [N,I]
  12. RewriteRule task-(\w*)-(\w+)\.html /index.php\?do=task&task_id=$1&view=$2 [N,I]
  13. RewriteRule service-(\w*)-(\w+)\.html /index.php\?do=service&sid=$1&view=$2 [N,I]
  14. RewriteRule help-(\w*)-(\w+)\.html /index.php\?do=help&fpid=$1&spid=$2 [N,I]
  15. RewriteRule article-(\w*)-(\w+)\.html /index.php\?do=article&page_size=$1&page=$2 [N,I]
  16. RewriteRule article_info-(\w*)-(\w+)\.html /index.php\?do=article&view=article_info&art_cat_id=$1&art_id=$2 [N,I]

  17. RewriteRule (task|shop|article|case|task_list|task_map|shop_list|shop_map|release|shop_release|help|login|link)\.html /index.php\?do=$1 [N,I]
复制代码

如果是IIS的httpd.conf:
  1. # Rewrite 系统规则请勿修改
  2. RewriteRule /index\.html /index.php [N,I]

  3. RewriteRule /task-([0-9]+)\.html /index.php\?do=task&task_id=$1 [N,I]
  4. RewriteRule /service-([0-9]+)\.html /index.php\?do=service&sid=$1 [N,I]
  5. RewriteRule /space-([0-9]+)\.html /index.php\?do=space&member_id=$1 [N,I]
  6. RewriteRule /help-([0-9]+)\.html /index.php\?do=help&fpid=$1 [N,I]
  7. RewriteRule /article_list-([0-9]+)\.html /index.php\?do=article&view=article_list&art_cat_id=$1 [N,I]
  8. RewriteRule /article_year-([0-9]+)\.html /index.php\?do=article&view=article_list&year=$1 [N,I]
  9. RewriteRule /(task_list|shop_list|shop)-(\w+)\.html /index.php\?do=$1&path=$2 [N,I]
  10. RewriteRule /article_info-(\w+)\.html /index.php\?do=article&view=article_info&art_id=$1 [N,I]

  11. RewriteRule /(task_list|shop_list)-(\w*)-(\w+)\.html /index.php\?do=$1&path=$2&indus_id=$3 [N,I]
  12. RewriteRule /task-(\w*)-(\w+)\.html /index.php\?do=task&task_id=$1&view=$2 [N,I]
  13. RewriteRule /service-(\w*)-(\w+)\.html /index.php\?do=service&sid=$1&view=$2 [N,I]
  14. RewriteRule /help-(\w*)-(\w+)\.html /index.php\?do=help&fpid=$1&spid=$2 [N,I]
  15. RewriteRule /article_info-(\w*)-(\w+)\.html /index.php\?do=article&view=article_info&art_cat_id=$1&art_id=$2 [N,I]

  16. RewriteRule /(task|shop|article|case|task_list|task_map|shop_list|shop_map|release|shop_release|help|login|link)\.html /index.php\?do=$1 [N,I]

复制代码

其它的静态化怎么写,自己试试吧,大体是一样,只是有小部分写法不太一样。

三、这样,网址就变成了很简单了,如:
task-5.html 表示第5个任务
service-3.html 表示第三个服务
task.html 为任务大厅
shop.html 为威客商城
task_list.html 为任务表示
还有象任务中的分类,以及任务中的稿件、留言、评论等都做相应的处理。
比原来客客的丑陋的伪静态好看多了。

这只是个简单的开始,以后再加强,把对于搜索引擎有益的页面都做出来,那些对搜索引擎无益的页面,无所谓。
2
一人天 发表于 2012-5-4 21:17:39 | 只看该作者
楼主很强,这样的很好看的
3
 楼主| MCCAD 发表于 2012-5-5 12:06:22 | 只看该作者
回复 2# 123466


    我的是IIS,使用的是.htaccess文件静态化,如果你是 httpd.conf静态化,那就需要在的网址前另上/号
如 RewriteRule index\.html /index.php [N,I]
需要改成 RewriteRule /index\.html /index.php [N,I]
4
admin 发表于 2012-5-5 15:02:25 | 只看该作者
客客的静态是程序生成的,确实不人写的。呵呵

楼主挖得很深.
5
 楼主| MCCAD 发表于 2012-5-6 07:58:18 | 只看该作者
已经做了最新的更新,目前基本把客客程序中需要静态化的地址都做了,包括了文章系统和帮助系统。
另外,还修正了:
1.对客客不规范写法的网址的支持,因为客客有时把网站的地址带上,有时又不带。
2.对锚链接的支持,如果有锚链接,静态化也会正常。
6
 楼主| MCCAD 发表于 2012-5-6 13:24:21 | 只看该作者
好了,已经调整过,看来客客的链接不太规范,因为一个页面竟然可以有多个不同的链接可以到达,这对于搜索引擎来说并不太友好
7
 楼主| MCCAD 发表于 2012-5-7 08:45:18 | 只看该作者
回复 12# 123466


    这个问题可能与本身客客的系统有关,我查一下。
我之前也发现有这个问题,不知道原来客客本身的静态化有没有这个问题。
8
 楼主| MCCAD 发表于 2012-5-7 21:49:24 | 只看该作者
回复 14# 123466


    这个地方已经静态化了。我不知道你在哪个页面看不到静态化,可以指出来。

另外,客客的代码非常不规范,所以经常有些地方没有按照规范书写,所以无法静态化。
就象个人空间吧,有时经常会无故在ID号后面加上空格,由于这样就不符合静态化的字符串要求,就静态化不了。
9
一人天 发表于 2012-5-7 22:20:00 | 只看该作者
回复  123466


    这个地方已经静态化了。我不知道你在哪个页面看不到静态化,可以指出来。

另外, ...
MCCAD 发表于 2012-5-7 21:49



   

我没看过代码,如果真是这样的话,我在考虑。。。。。。。。。。。。
10
31wb 发表于 2012-5-9 17:09:05 | 只看该作者
回复 1# MCCAD
如果是Linux服务器软件:Apache 规则又是如何的呢?
123下一页
您需要登录后才可以回帖   登录 注册

高级模式

|小黑屋|官方微博|QQ空间|每日签到|客客专业威客|众包建站系统 ( 鄂ICP备11009411号-1 )

Powered by Discuz! X3.2 © 2001-2018 Comsenz Inc.