基于用户代理的移动网站重定向

时间:2011-12-02 20:55:58

标签: .htaccess mobile web dns redirect

说我有两个不同的域名:

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

为我的网站。

我希望域名n.1与我的网站的完整版本(主要由桌面用户代理访问)和域名n.2相关联,以与其移动版本相关联(旨在主要访问由移动用户代理商。)

这两个版本都驻留在运行Apache webserver实例的外部主机上,我无法直接控制,但我可以发布.htaccess个文件,因此我希望它们能够控制域重定向的东西(I不想使用Javascript和PHP服务器端逻辑)

外部主机上的目录结构是:

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)

和映射是:

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

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

A)当用户要求提供网址http://sub.test.org时:

  1. 如果当前网址为http://m.sub.test.org/*(这意味着:如果用户当前正在使用移动版本),那么请点击http://sub.test.org/index.html
  2. ELSE:
    1. 如果用户代理是移动的,那么重定向到网址http://m.sub.test.org
    2. ELSE投放页面http://sub.test.org/index.html
  3. B)当用户请求网址http://m.sub.test.org时 - 无论用户代理是什么 - 用户都应重定向到网址http://sub.test.org

    我的问题:

    • 关联的.htaccess文件的syintax是什么?
    • 我需要多个吗?
    • 我应该把它放在哪里?

    任何帮助/代码提示都会非常感激,因为我对Apache .htaccess文件和regexp有一些经验!提前谢谢。

1 个答案:

答案 0 :(得分:1)

相关问题