zoukankan      html  css  js  c++  java
  • destoon自定义文件的伪静态地址优化

    destoon自定义文件的伪静态优化

    destoon给出了一个自定义文件传参的方式

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

    目前的处理方式:index.php?catid=0&areaid=0&z=0的伪静态处理结果为

    index-htm-catid-0-areaid-0-z-0.html

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

    我现在增加一个方法

    把类似这样的长网址search-htm-areaid-1-catid-0-order-0-kw-.html简化成search-htm-areaid-1.html

    rewrite是原方法,在方法体中增加一个getUrlKeyValue($url)来处理
    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;
    }

    服务端htaccess对地址的接收:

    RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
    $DT_QST = addslashes($_SERVER['QUERY_STRING']);

    然后rewirte.inc.php文件对query_string做接收处理

    defined('IN_DESTOON') or exit('Access Denied');
    $pstr = '';
    if(isset($_SERVER['UNENCODED_URL']) && strpos($_SERVER['QUERY_STRING'], '-htm-') !== false) $_SERVER['QUERY_STRING'] = substr($_SERVER['UNENCODED_URL'], strpos($_SERVER['UNENCODED_URL'], '-htm-') + 5);//IIS7+
    if($_SERVER['QUERY_STRING']) {
        if(preg_match("/^(.*).html(?(.*))*$/", $_SERVER['QUERY_STRING'], $_match)) {
            $pstr = $_match[1];
        } else if(preg_match("/^(.*)/$/", $_SERVER['QUERY_STRING'], $_match)) {
            $pstr = $_match[1];
        }
    } else if($_SERVER["REQUEST_URI"] != $_SERVER["SCRIPT_NAME"]) {
        $string = str_replace($_SERVER["SCRIPT_NAME"], '', $_SERVER["REQUEST_URI"]);
        if($string && preg_match("/^/(.*)/$/", $string, $_match)) $pstr = $_match[1];
    }
    
    if($pstr && strpos($pstr, '-') !== false) {
        $_GET = array();
        $pstr = explode('-', $pstr);
        $pstr_count = count($pstr);
        if($pstr_count%2 == 1) --$pstr_count;
        for($i = 0; $i < $pstr_count; $i++) { $_GET[$pstr[$i]] = $MQG ? addslashes($pstr[++$i]) : $pstr[++$i]; }
    }
    ?>


  • 相关阅读:
    Unix命令大全
    vs2008 与 IE8出现的兼容性问题
    Java 创建文件、文件夹以及临时文件
    如何修改Wamp中mysql默认空密码
    PAT 乙级真题 1003.数素数
    Tags support in htmlText flash as3
    DelphiXE4 FireMonkey 试玩记录,开发IOS应用 还是移植
    10 Great iphone App Review sites to Promote your Apps!
    HTML tags in textfield
    Delphi XE4 IOS 开发, "No eligible applications were found“
  • 原文地址:https://www.cnblogs.com/keleyu/p/11757428.html
Copyright © 2011-2022 走看看