基于用户代理手机网站重定向 [英] Mobile website redirection based on user agent

查看:158
本文介绍了基于用户代理手机网站重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有两个不同的领域:

  1)http://sub.test.org
 2)http://m.sub.test.org
 

我的网站。

我想域N.1要关联到全版本我的网站(意在主要访问的桌面用户代理)和域N.2要关联到其移动版本(旨在用于需要主要访问的移动用户代理)。

这两个版本的驻留它运行Apache网络服务器的我不能直接控制的实例在外部主机上,但我能张贴的.htaccess 文件,因此,我希望他们能够控制域重定向的东西(我不想使用JavaScript既不PHP服务器端逻辑)

在外部主机上的目录结构,说:

 目录/  - >包含完整版网站的网页和资源
                (index.html的是入口点)

目录/移动 - >包含完整版网站的网页和资源
                      (index.html的是入口点)
 

和映射是:

  http://sub.test.org  - > /index.html
http://m.sub.test.org  - > /mobile/index.html
 

现在,我需要的方案如下:

A)当用户请求的URL http://sub.test.org

  1. 如果当前的URL是 http://m.sub.test.org/* (这意味着:如果用户是目前进入移动版)接发球页 http://sub.test.org/index.html
  2. ELSE:
    1. 如果用户代理是移动然后重定向到URL http://m.sub.test.org
    2. ELSE服务页面 http://sub.test.org/index.html

B)当用户请求的URL http://m.sub.test.org - 不管用户代理是什么 - 用户应该被重定向到URL http://sub.test.org

我的问题:

  • 什么是相关联的的.htaccess 文件的syintax?
  • 请我需要一个以上的?
  • 我应该在哪里把它/他们?

任何帮助/ code暗示将是非常美联社preciated,因为我真的与Apache 的.htaccess 文件和正则表达式一些经验!先谢谢了。

解决方案

Say I've got two distinct domains:

 1) http://sub.test.org
 2) http://m.sub.test.org

for my website.

I want domain n.1 to be associated to the full-version of my website (intended to be mainly visited by desktop user agents) and domain n.2 to be associated to its mobile-version (intended to be mainly visited by mobile user agents).

Both of the versions reside on an external host which runs an instance of Apache webserver I can't control directly, but I am able to post .htaccess files and therefore I want them to control domain redirecting stuff (I don't want to use Javascript neither PHP server-side logic)

The directory structure on the external host is, say:

directory / --> contains full-version website's pages and resources 
                (index.html is the entry-point)

directory /mobile --> contains full-version website's pages and resources 
                      (index.html is the entry-point)

and the mappings are:

http://sub.test.org -> /index.html
http://m.sub.test.org -> /mobile/index.html

Now, my desired scenarios are as follows:

A) When user asks for URL http://sub.test.org:

  1. IF current URL is http://m.sub.test.org/* (this means: if user is currently into the mobile-version) THEN serve page http://sub.test.org/index.html
  2. ELSE:

    1. IF user agent is mobile THEN redirect to URL http://m.sub.test.org
    2. ELSE serve page http://sub.test.org/index.html

B) When user asks for URL http://m.sub.test.org - no matter what the user agent is - user should be redirected to URL http://sub.test.org.

My questions:

  • What would be the syintax of the associated .htaccess file?
  • Do I need more than one?
  • Where should I place it/them ?

Any help/code hint would be really appreciated, because I have really a few experience with Apache .htaccess files and regexps! Thanks in advance.

解决方案

这篇关于基于用户代理手机网站重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆