简体   繁体   English

桌面和移动网站,相同的网址,如何相互链接?

[英]Desktop & mobile site, same urls, how to link back to each other?

We are in the process of getting a mobile version of our site up and going. 我们正在准备移动版本的网站。 For various reasons we are investigating the "same URL, different content" structure via User Agent detection. 出于各种原因,我们正在通过用户代理检测来研究“相同的URL,不同的内容”结构。 No problems there, we're comfortable setting a cookie depending on UA settings and using this cookie to determine what content/css/etc to use. 没有问题,我们很乐意根据UA设置设置cookie并使用此cookie来确定要使用的内容/ css / etc。

The problem is though, we want to provide a link back to desktop version from the mobile page, and vice versa. 但问题是,我们希望从移动页面提供返回桌面版本的链接,反之亦然。 We don't want to just link to the homepage, but to the same page, just in the other environment. 我们不想只是链接到主页,而是链接到同一页面,只是在其他环境中。

We were thinking about making the links contain a $_GET parameter 我们正在考虑使链接包含$ _GET参数

<a href="....html&mob=1">...</a> //mobile page, user wants desktop, AND
<a href="....html&mob=2">...</a> //desptop page, user wants mobile

Then in our prepend we would check for the $_GET parameter, if found, depending on it's status, to set or unset our cookie, and then do a redirect to the HTTP_REFERRER (the same page as they were just on). 然后在我们的前置中,我们将检查$ _GET参数,如果找到,取决于它的状态,设置或取消设置我们的cookie,然后重定向到HTTP_REFERRER(与它们刚刚打开的同一页面)。

The question is though, does anyone know how this will affect SEO/bots? 问题是,有没有人知道这将如何影响SEO /机器人?

Is there a best practice for serving different content on the same url, AND have a link to the other version. 是否有在同一网址上提供不同内容的最佳做法,并且具有指向其他版本的链接。

Any input would be greatly appreciated. 任何投入将不胜感激。 Thanks in advance! 提前致谢!

UPDATE - OUR CODE FOR DETECTING MOBILE USERS AND THEIR CHOICE 更新 - 我们的代码,用于检测移动用户及其选择

// First page load, redirect if mobile
if(!isset($_SESSION['mobile'])){
    // SCRIPT SOURCED FROM: http://code.google.com/p/php-mobile-detect/
    include_once(INCL_PREP . "lib/Mobile_Detect.php");
    $detect = new Mobile_Detect();
    // if mobile device, but NOT tablet (they handle desktop versions just fine!)
    if ($detect->isMobile()  && !$detect->isTablet()) {
    $_SESSION['mobile'] = 1;
    $redirectURL= ...; // code removed for sake of space and relevancy
    header("location:$redirectURL");
}else{
    $_SESSION['mobile'] = 2;
}
// Get the $_SESSION['mobile'] status by the $_GET parameter
if($_GET['mobile'] == "on"){
     $_SESSION['mobile'] = 1;
}else{
        $_SESSION['mobile'] = 2;
}

So, the mobile version has $_GET a get parameter, and using this and $_SESSION we can auto redirect on page load, and they can also swap between the mobile and desktop version without a problem. 所以,移动版本有$ _GET一个get参数,使用这个和$ _SESSION我们可以自动重定向页面加载,他们也可以在移动和桌面版本之间交换而没有问题。

Thanks to the input people. 感谢投入的人。

'Technically' you're not using the "same URL" - query string variants are actually treated as different URLs by search bots. '技术上'你没有使用“相同的URL” - 查询字符串变体实际上被搜索机器人视为不同的URL。

If you're trying to manage different URLs for mobile/desktop users and want to ensure that Google "sees" the right version, then read the following resource: https://developers.google.com/webmasters/smartphone-sites/details 如果您尝试为移动/桌面用户管理不同的网址,并希望确保Google“看到”正确的版本,请阅读以下资源: https//developers.google.com/webmasters/smartphone-sites/details

Half way down is the explanation on how to use the rel="alternate" and rel="canonical" for exactly the scenario you are describing. 一半是关于如何使用rel="alternate"rel="canonical" ,正是您所描述的场景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM