说我有两个不同的领域:
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
:
http://m.sub.test.org/*
(这意味着:如果用户是目前进入移动版)接发球页 http://sub.test.org/index.html
ELSE:
如果用户代理是移动然后重定向到URL http://m.sub.test.org
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
:
http://m.sub.test.org/*
(this means: if user is currently into the mobile-version) THEN serve page http://sub.test.org/index.html
ELSE:
IF user agent is mobile THEN redirect to URL http://m.sub.test.org
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.
http://httpd.apache.org/docs/current/howto/htaccess.html You would most likely need 2 place one it in the root and one in /mobile