繁体   English   中英

根据URL将用户从桌面站点重定向到移动站点

[英]redirect users from desktop site to mobile site based on URL

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

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

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

这个答案可以在我的drupal网站上获取我的绝对URL: 如何获取Drupal页面的完整URL?

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

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

我确定这是基本的PHP事情,但是我很困惑,确实可以使用一些指导,以便我朝正确的方向前进。 我也尝试了贡献性drupal模块,但是因为我有多语言站点,所以我不能使用它们(它们不支持这些语言)

我想我明白您的意思:

// 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}");
}

暂无
暂无

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

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