简体   繁体   English

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

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

I've got a mixed Drupal6 and php redirect question that I really need help with. 我有一个混合的Drupal6和php重定向问题,我确实需要帮助。

I've got a Drupal 6 site, with a smaller mobile site on a subdomain. 我有一个Drupal 6网站,在子域上有一个较小的移动网站。 I'm building a custom module to redirect visitors of the site to the mobile site based on device and location (US users only). 我正在构建一个自定义模块,用于根据设备和位置(仅限美国用户)将网站的访问者重定向到移动网站。

I'm using mobile detect to discover the user's deviceL: https://github.com/serbanghita/Mobile-Detect 我正在使用移动检测来发现用户的设备L: https : //github.com/serbanghita/Mobile-Detect

and this answer to get my absolute URL on my drupal site: How to get the full URL of a Drupal page? 这个答案可以在我的drupal网站上获取我的绝对URL: 如何获取Drupal页面的完整URL?

So far both pieces are working fine, but I'm not sure how to write the lines to go from one location to the next. 到目前为止,这两部分都工作正常,但是我不确定如何编写从一个位置到另一位置的行。 I've got about 8 specific urls that need to be redirected that would look something like this: 我有大约8个需要重定向的特定网址,看起来像这样:

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

I'm sure it's a basic PHP thing, but I'm stumped and could really use some guidance so I can move in the right direction. 我确定这是基本的PHP事情,但是我很困惑,确实可以使用一些指导,以便我朝正确的方向前进。 I've also tried contributed drupal modules, but because I have multi-languages sites I can't use them (they don't support the languages) 我也尝试了贡献性drupal模块,但是因为我有多语言站点,所以我不能使用它们(它们不支持这些语言)

I think I understand what you are saying: 我想我明白您的意思:

// 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