最近研究dt6.0,官方内核默认是把搜索页屏蔽的,但是做seo的人都知道,搜索页聚合是争取排名的好地方,所以我就二次开发搜索页,具体可以查看前几期分享的,今天说说关于搜索的canonical的url乱码问题。
首页第一步:找到api/extend.func.php下在最后面插入以下函数,本函数是自己写的,如有其他更精简写法可以一起交流。
if( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ){ // IIS Mod-Rewrite $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL']; } else if( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) { // IIS Isapi_Rewrite $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL']; } else { // Use ORIG_PATH_INFO if there is no PATH_INFO ( !isset( $_SERVER['PATH_INFO']) && isset( $_SERVER['ORIG_PATH_INFO'] ) ) && ( $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'] ); // Some IIS + PHP configurations puts the script-name in the path-info ( No need to append it twice ) if ( isset( $_SERVER['PATH_INFO'] ) ) { ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] ) ? ( $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'] ) : ( $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'] ); } // Append the query string if it exists and isn't null ( isset($_SERVER['QUERY_STRING'] ) && !empty( $_SERVER['QUERY_STRING'] ) ) && ( $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'] ); }
然后在搜索模板下添加:
<link rel="canonical" href="<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];?>" />
这样就好了,具体演示:
http://zhimo.yuanzhumuban.cc/news/search-htm-kw-%E8%AF%86%E5%88%AB.html