zblogphp文章内容页采用二级域名方法打开

来自:互联网
时间:2018-09-01
阅读:

此方法需要改zblogphp内核,本文仅做记录参考,本方法很不实用,不推荐使用本方法。

最终展示效果。。比如。某文章别名为song,相应的,通过song.songzhenjiang.cn打开的就是本篇文章。

本方法需要开启伪静态,然后把文章页的伪静态改成

{%host%}post/{%alias%}.html

在zb_system/function/c_system_event.php页面找到ViewIndex函数。

default:后面添加。

$d = array(); 
if (preg_match("/^(.+).songzhenjiang.cn/",$zbp->host,$d) !==1){ 
}else{ 
    $ejym= str_replace("http://", '',$d[1]); 
    if($ejym!="www"){ 
    ViewAuto1($ejym); 
    }else{ 
        ViewList(null, null, null, null, null); 
    } 
}

然后,添加ViewAuto1函数

function ViewAuto1($inpurl) { 
    global $zbp; 
    $inpurl="/post/".$inpurl.".html"; 
    $url = GetValueInArray(explode('?', $inpurl), '0'); 
    if ($zbp->cookiespath === substr($url, 0, strlen($zbp->cookiespath))) { 
        $url = substr($url, strlen($zbp->cookiespath)); 
    } 
    $url = trim(urldecode($url), '/'); 
    if ($url == '' || $url == 'index.php') { 
        $r ="/(?J)^post/(?P<alias>[^/]+).html$/"; 
        $m = array(); 
        $result = ViewPost($m, null, true); 
         
        return null; 
    } 
    if ($zbp->option['ZC_STATIC_MODE'] == 'REWRITE') { 
        $r = UrlRule::OutputUrlRegEx($zbp->option['ZC_ARTICLE_REGEX'], 'article'); 
        $m = array(); 
        if (preg_match($r, $url, $m) == 1) { 
            $result = ViewPost($m, null, true); 
            if ($result == false) { 
                $zbp->ShowError(2, __FILE__, __LINE__); 
            } 
            return null; 
        } 
    } 
    foreach ($GLOBALS['hooks']['Filter_Plugin_ViewAuto_End'] as $fpname => &$fpsignal) { 
        $fpreturn = $fpname($url); 
        if ($fpsignal == PLUGIN_EXITSIGNAL_RETURN) { 
            $fpsignal = PLUGIN_EXITSIGNAL_NONE; 
            return $fpreturn; 
        } 
    } 
    if (isset($zbp->option['ZC_COMPATIBLE_ASP_URL']) && ($zbp->option['ZC_COMPATIBLE_ASP_URL'] == true)) { 
        if (isset($_GET['id']) || isset($_GET['alias'])) { 
            ViewPost(GetVars('id', 'GET'), GetVars('alias', 'GET')); 
            return null; 
        } elseif (isset($_GET['page']) || isset($_GET['cate']) || isset($_GET['auth']) || isset($_GET['date']) || isset($_GET['tags'])) { 
            ViewList(GetVars('page', 'GET'), GetVars('cate', 'GET'), GetVars('auth', 'GET'), GetVars('date', 'GET'), GetVars('tags', 'GET')); 
            return null; 
        } 
    } 
    $zbp->ShowError(2, __FILE__, __LINE__); 
}
返回顶部
顶部