zoukankan      html  css  js  c++  java
  • DT6.0下搜索页解决canonical获取乱码问题

      最近研究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

  • 相关阅读:
    码农的自我修养
    工程化编程实战callback接口学习笔记
    eval代码执行漏洞
    CTF_show WEB1通过order排序读取数据库数据(特定场景)
    Python的ico_hash计算脚本
    FOFA网页爬取最新 批量版本
    利用Python爬取fofa网页端数据
    利用Python进行Payload分离免杀
    [Gym101653Q]Number Game
    傅里叶变换
  • 原文地址:https://www.cnblogs.com/68xi/p/9196569.html
Copyright © 2011-2022 走看看