【问题标题】:redirect users from desktop site to mobile site based on URL根据 URL 将用户从桌面站点重定向到移动站点
【发布时间】:2013-08-20 21:04:26
【问题描述】:

我有一个混合的 Drupal6 和 php 重定向问题,我真的需要帮助。

我有一个 Drupal 6 网站,在子域上有一个较小的移动网站。 我正在构建一个自定义模块,以根据设备和位置(仅限美国用户)将网站访问者重定向到移动网站。

我正在使用移动检测来发现用户的设备L:https://github.com/serbanghita/Mobile-Detect

这个答案可以在我的 drupal 网站上获取我的绝对 URL:How to get the full URL of a Drupal page?

到目前为止,这两个部分都工作正常,但我不确定如何编写从一个位置到下一个位置的行。 我有大约 8 个需要重定向的特定 url,看起来像这样:

http://desktopsite.com/specific-page -> http://m.mobilesite.com/specific-page

我确信这是一个基本的 PHP 东西,但我很难过,真的可以使用一些指导,这样我就可以朝着正确的方向前进。我也尝试过贡献的 drupal 模块,但是因为我有多语言网站,所以我无法使用它们(它们不支持这些语言)

【问题讨论】:

    标签: php mobile drupal-6 url-redirection


    【解决方案1】:

    我想我明白你在说什么:

    // Make a mobile detect object
    $detect = new Mobile_Detect();
    // Check the device
    if($detect->isMobile()){
        // Here is where you put the page you have 
        // i.e. http://desktopsite.com/specific-page;
        $location = "http://desktopsite.com/specific-page;";
        // We need to swap the url in that $location variable
        $location = str_replace("http://desktopsite","http://m.mobilesite",$location);
        // Then to a classic redirect
        header("Location: {$location}");
    }
    

    【讨论】:

    • 这看起来确实是它的开始。在处理 12 个不同的 URL(虽然只有 1 个桌面站点到 1 个移动站点,而不是多个不同的站点)时,我将如何使用它作为基础?
    • 您提到您已经可以获取页面的绝对 url,所以在我放置 $location = "http://desktopsite.com/specific-page"; 的位置您将放置 $location = $absolute_url_you_got; 然后脚本的其余部分将替换 "http://desktopsite" 在URL 以"http://m.mobilesite" 开头(我复制了您的示例,m.mobilesite 可能是错字,可能应该是“m”或“mobilesite”,但不能同时使用)。然后header 部分将重定向到该页面。
    • 因此,如果您将其放在要重定向的任何页面的开头,并进行更改以获取您所在页面的绝对网址,它应该可以正常工作。
    • 非常感谢您的帮助,这确实让我走上了正轨:)
    猜你喜欢
    • 1970-01-01
    • 2014-07-12
    • 1970-01-01
    • 2017-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多