让PHPCMS V9的动态网址更加干净的办法

PHPCMS V9默认的动态页面网址太长了(比如默认的栏目网址为:/index.php?m=content&c=index&a=lists& amp;catid=9,内容页面网址为:/index.php?m=content&c=index&a=show& catid=11&id=46),通过修改,我们可以用更加干净、简短的网址(/index.php/a/lists/catid/9/和 /index.php/a/show/catid/11/id/46/index.html)来访问它们。

经过这样修改是不是更好看了 是不是更能适合于SEO了呢

修改步骤

版本:PHPCMS V9

1:

打开phpcmslibsfunctionsextention.func.php文件,在末尾的“?>”前面添加以下代码:

global $_URLCFG;

$_URLCFG=array();

$_URLCFG['urlmode']=2;

$_URLCFG['urlsuffix']='index.html';

getQueryString();

/**

* 获得友好的URL访问

*

* @access  public

* @return  array

*/

function getQueryString(){

global $_URLCFG;

if($_URLCFG['urlmode']!=2) return $_GET;

    $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');

if(!$path){

$script_name=$_SERVER['SCRIPT_NAME'];//获取当前文件的路径

$path= $_SERVER['REQUEST_URI'];//获取完整的路径,包含"?"之后的字符串

//去除url包含的当前文件的路径信息

if($path && @strpos($path,$script_name,0)!==false)

{

if($path!=$script_name) $path=substr($path,strlen($script_name));

}else{

$script_name=str_replace(basename($script_name),'',$script_name);

if($path && @strpos($path,$script_name,0)!==false){

$path=substr($path,strlen($script_name));

}

}

//第一个字符是'/',则去掉

if($path[0]!='/'){

$path='/'.$path;

}

if(strpos($path,'/index.php')===0) $path=preg_replace('|^/index\.php|','',$path);

//去除问号后面的查询字符串

if($path && false!==($pos=@strrpos($path,'?'))){

$path=substr($path,0,$pos);

}

}

    $_SGETS = explode('/',substr($path,1));

    $_SLEN =  count($_SGETS);

    $_SGET =& $_GET;

    for($i=0;$i<$_SLEN;$i+=2){

        if(!empty($_SGETS[$i]) && !empty($_SGETS[$i+1])) $_SGET[$_SGETS[$i]]=$_SGETS[$i+1];

    }

 

    $_SGET['m'] = !empty($_SGET['m']) && is_string($_SGET['m']) ? trim($_SGET['m']) : '';

$_SGET['c'] = !empty($_SGET['c']) && is_string($_SGET['c']) ? trim($_SGET['c']) : '';

    $_SGET['a'] = !empty($_SGET['a']) && is_string($_SGET['a']) ? trim($_SGET['a']) : '';

    return $_SGET;

}

2:

进入后台-》扩展-》修改URL规则:

3、将内容模块原来默认的动态category URL规则修改为:

/index.php/a/lists/catid/{$catid}/index.html|/index.php/a/lists/catid/{$catid}/page/{$page}/index.html

4、将内容模块原来默认的动态show URL规则修改为:

index.php/a/show/catid/{$catid}/id/{$id}/index.html|index.php/a/show/catid/{$catid}/id/{$id}/page/{$page}/index.html

5、进入“内容”管理页面,分别更新栏目缓存和更新URL网址

原文地址:https://www.cnblogs.com/cms100/p/3280706.html