这两个月来写的文章愈来愈少了,不是懒,由于太忙了--为客户赶作网站。由于客户指定要使用phpcms v9,还要求使用phpcms v9_42版本实现tag伪静态,在接手的时候phpcms v9_42是最新版本,而如今phpcms官方已经发布phpcms v9_5.X了。对于phpcms v9实现tag伪静态的实现方法,百度一下就会一大堆,但倒是phpcms v9_2X版本的,并且最终实现的结果是:域名/关键词_6_1.html,我看得都以为别扭--下面我会把URL的尾巴砍得更短些。php
phpcms v9_42版本是目前(2013-10-29)最新的版本,相比于phpcms v9_2X的tag模块的代码,改动较大,因而乎,百度得来的phpcms v9_2X版本tag伪静态的实现方法就OUT了。怎么办呢?下面我就把建站过程当中整理的phpcms v9_42版本下tag伪静态的实现方法放出来,绝对是最新(2013.12.10)的了。html
TAG模块伪静态设置web
一、添加url规则测试
在后台->扩展->url规则里添加一个新的规则用于评论模块,以下所示:网站
{$tag}_{$page}.html编码
添加完成后记住前面的id号,好比32。url
二、在代码里写入url规则spa
打开phpcms/modules/content/tag.php文件,找到:操作系统
1 |
$infos = $keyword_data_db ->listinfo( $where , '`id` DESC' , $page , $pagesize ); |
这一行往上面添加如下代码:code
1 |
$urlrules = getcache( 'urlrules' , 'commons' ); |
2 |
$urlrule = $urlrules [32]; //调用url规则 |
而后再把
1 |
$infos = $keyword_data_db ->listinfo( $where , '`id` DESC' , $page , $pagesize ); |
改为
1 |
$infos = $keyword_data_db ->listinfo( $where , '`id` DESC' , $page , $pagesize , '' , '9' , $urlrule ,Array( 'tag' =>urlencode( $tag ))); |
目的就是往查询语句里面添加前面设置的url规则。
三、修改模板
打开phpcms\templates\default\content\show.html,找到:
1 |
{APP_PATH}index.php?m=content&c=tag&a=lists&tag={urlencode( $keyword )} |
改为
{APP_PATH}{urlencode($keyword)}_1.html
打开phpcms\templates\default\content\tag.html,把分页标签
1 |
{ $pages } |
改为
1 |
{ str_replace ( "_0.html" , "_1.html" , $pages )} |
四、在.htaccess文件里加入URL规则
在网站的根目录的.htaccess文件(没有的本身建)加入如下URL规则
1 |
RewriteRule ^(.*)_([0-9]+).html index.php?m=content&c=tag&a=lists&tag= $1 &page= $2 |
最后显示出来的URL样式以下:http:/w3note.com/关键词_1.html
可能会遇到的问题
在操做系统:Linux ,点击标签时会出现找不到此关键字的提示,缘由是转码问题,而在本地测试则没有这种状况。
解决的办法
打开phpcms/modules/content/tag.php
找到
1 |
$tag = safe_replace( addslashes ( $_GET [ 'tag' ])); |
在其下面添加以下代码
1 |
$tag = iconv( "gb2312" , "utf-8" , $tag ); //转编码 |
若是还不行,不防试着调换"gb2312","utf-8"的位置。
转载:w3note.com/web/133.html