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)来处理

 

转自:http://www.kaotop.com/it/218870.html

 

在/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;
} 
posted @ 2021-03-17 10:04  圆柱模板  阅读(92)  评论(0编辑  收藏  举报