根据URL将用户从桌面站点重定向到移动站点(redirect users from desktop site to mobile site based on URL)

编程入门 行业动态 更新时间:2024-10-23 07:27:35
根据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模块,但因为我有多语言网站我不能使用它们(它们不支持这些语言)

I've got a mixed Drupal6 and php redirect question that I really need help with.

I've got a Drupal 6 site, with a smaller mobile site on a subdomain. 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

and this answer to get my absolute URL on my drupal site: How to get the full URL of a Drupal page?

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:

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. 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)

最满意答案

我想我明白你在说什么:

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

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

更多推荐

本文发布于:2023-04-29 11:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336382.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:站点   重定向   桌面   用户   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!