【发布时间】:2012-01-11 20:22:37
【问题描述】:
假设我有两个不同的域:
1) http://sub.test.org
2) http://m.sub.test.org
我的网站。
我希望域 n.1 关联到我的网站的完整版本(主要由桌面用户代理访问),域 n.2 关联到其移动版本(主要访问由移动用户代理)。
这两个版本都驻留在运行我无法直接控制的 Apache 网络服务器实例的外部主机上,但我能够发布 .htaccess 文件,因此我希望它们控制域重定向的东西(我不不想使用 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) 当用户请求 URL http://sub.test.org:
- IF 当前 URL 是
http://m.sub.test.org/*(这意味着:如果用户当前进入移动版) THEN 提供页面http://sub.test.org/index.html - 否则:
- 如果用户代理是移动的,那么重定向到 URL
http://m.sub.test.org - ELSE 服务页面
http://sub.test.org/index.html
- 如果用户代理是移动的,那么重定向到 URL
B) 当用户请求 URL http://m.sub.test.org - 无论用户代理是什么 - 用户都应该被重定向到 URL http://sub.test.org。
我的问题:
- 关联的
.htaccess文件的语法是什么? - 我需要多个吗?
- 我应该把它/它们放在哪里?
非常感谢任何帮助/代码提示,因为我对 Apache .htaccess 文件和正则表达式有一些经验!提前致谢。
【问题讨论】:
标签: .htaccess mobile web dns redirect