北京赛车pk10开奖结果

CMS插件分享网

影子是一个会撒谎的精灵,它在虚空中流浪和等待被发现之间;在存在与不存在之间....

位置:主页 > 织梦二次开发 >

dedecms的电脑站路径跳转手机站路径的方法

发布时间:2019-12-05 18:04作者:√無∑情—浏览(57)

    首先说下,手机站有的是动态的,也有是静态的。下面分两部来说:

    PC站跳转到动态手机站:

    织梦PC端首页跳转到手机站首页代码(需要加到pc站头部中):
    <meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobileurl/}/index.php">
    <script type="text/javascript">if(window..toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window..href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window..href="{dede:global.cfg_mobileurl/}/index.php";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>

    织梦PC端列表页跳转到手机站列表页代码(需要加到pc站列表页头部中):

    <meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobileurl/}/list.php?tid={dede:field.id/}">
    <script type="text/javascript">if(window..toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window..href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window..href="{dede:global.cfg_mobileurl/}/list.php?tid={dede:field.id/}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
    织梦PC端内容页跳转到手机站内容页代码(需要加到pc站内容页头部中):
    <meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobileurl/}/view.php?aid={dede:field.id/}">
    <script type="text/javascript">if(window..toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window..href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window..href="{dede:global.cfg_mobileurl/}/view.php?aid={dede:field.id/}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>

    PC站跳转到静态手机站:

    织梦PC端首页跳转到手机站首页代码(需要加到pc站头部中):
    <meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobileurl/}">
    <script type="text/javascript">if(window..toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window..href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window..href="{dede:global.cfg_mobileurl/}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
    织梦PC端列表页跳转到手机站列表页代码(需要加到pc站列表页头部中):
    <meta http-equiv="mobile-agent" content="format=xhtml;url={dede:type}[field:typeurl function = "str_replace('https://www.pinjieping.vip' , 'http://m.pinjieping.vip' , @me)"/]{/dede:type}">
    <script type="text/javascript">if(window..toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window..href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window..href="{dede:field.typeurl function="{dede:type}[field:typeurl function = "str_replace('http://m.pinjieping.vip' , 'https://www.pinjieping.vip' , @me)"/]{/dede:type}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
    织梦PC端内容页跳转到手机站内容页代码(需要加到pc站内容页头部中):
    <meta http-equiv="mobile-agent" content="format=xhtml;url={dede:field.arcurl function="str_replace('https://www.pinjieping.vip' , 'http://m.pinjieping.vip' , @me)"/}">
    <script type="text/javascript">if(window..toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window..href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window..href="{dede:field.arcurl function="str_replace('https://www.pinjieping.vip' , 'http://m.pinjieping.vip' , @me)"/}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
    另外还有一个简单的,只必把下面的代码放入到每个页面上,也可以实现跳转:(不管是静态动态都能用)
    <script>
          var html=document.getElementsByTagName("html")[0],domain="https://www.pinjieping.vip";
          html.setAttribute("class",html.className.replace(/no-js/,''));
                if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){  
            if(window..href.indexOf("?for=m")<0){
              try{
                if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){ 
                                  window..href="http://m.pinjieping.vip"+window..pathname+window..search;
                              }
              }catch(e){}
            }
          }
    </script>

    说明:请把上面的,www.pinjieping.vip    m.pinjieping.vip  域名换成自己的

    最后,PC站与M站的SEO设置

    虽然页面不一样,但大体上是一样,蜘蛛会重复收录PC端和WAP移动端,容易造成分权。

    一般的处理办法是,PC用alternate声明与之对应的移动端URL,移动端用canonical声明只收录PC端的URL。

    WAP移动端页面SEO设置
    
    在</head>之前添加canonical声明。
    
    <link rel="canonical" href="http://www.自己的域名.com/">
    
    
    电脑端页面SEO设置
    
    在</head>之前添加alternate声明。
    
    <link rel="alternate" href="http://m.自己的域名.com/">
分享到:QQ空间新浪微博腾讯微博人人网微信