栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 软件开发 > 后端开发 > PHP > php开源框架 > destoon

destoon伪静态地址空值优化

destoon 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

destoon伪静态地址空值优化

   目前的处理方式:index.php?catid=0&areaid=0&kw=墙体广告 的伪静态处理结果为

index-htm-kw-墙体广告-catid-0-areaid-0.html

但是这种格式不是特别好,因为如果值为0或者值为空的时候, 表示值不存在,如果是多重条件的组合,会生成一长串空值地址:

现在增加一个方法

把类似这样的长网址sell/search-htm-list-0-kw-墙体广告-catid-0-areaid-0.html  简化成 search-htm-kw-墙体广告.html

rewrite是原方法,在方法体中增加一个getUrlKeyValue($url)来处理

 

在/include/global.func.php 有个rewirte函数来处理

function rewrite($url, $encode = 0) {
    if(!RE_WRITE) return $url;
    if(RE_WRITE == 1 && strpos($url, 'search.php') !== false) return $url;
    if(strpos($url, '.php?') === false || strpos($url, '=') === false) return $url;
    $url= getUrlKeyValue($url);//这里增加一个过滤方法解决值为空或0的问题
    $url = str_replace(array('+', '-'), array('%20', '%20'), $url);
    $url = str_replace(array('.php?', '&', '='), array('-htm-', '-', '-'), $url).'.html';
    return $url;
}


在本文件最后加上一个函数

function getUrlKeyValue($url){
    $result = '';
    $mr = preg_match_all('/(\?|&)(.+?)=([^&?]*)/i', $url, $matchs);
    if ($mr !== false) {
        for ($i = 0; $i < $mr; $i++) { if($matchs[3][$i]) { $result.=$matchs[2][$i].'='.$matchs[3][$i].'&'; } } } $rootStr = substr($url,0,strpos($url, '.php?')+5);
    $result = $rootStr.rtrim($result,'&');
    return $result;
}

   

转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/218870.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号