[英]Document root for mobile version (.htaccess?)
我有一个网上商店,自从Google决定推广网页的移动版本以来,我正在开发m.example.com
。
这是窍门。 我不想, m.
域。 我想要的是,当有用户来时,我检查用户代理,如果它来自移动设备,我将显示移动版本,如果来自桌面,则显示桌面版本。
但是,我想向用户使用完全相同的网址。 因此, http://example.com/contact/
将是台式机用户和移动用户的网址。
该页面的移动版本位于./mobile/
子目录./mobile/
。
如果有人来自移动设备,但可以保留原始URL,则是否可能以某种方式强制apache,更改文档根目录?
例如:
http://example.com/contact/
应该运行/var/apache/example.com/mobile/contact.php
,但对于台式机版本,应该运行/var/apache/example.com/contact.php
? 如前所述,URL是相同的。
如果问题不清楚,请发表评论。
像这样吗 (从此答案中整理,然后仅执行RewriteRule
)
RewriteEngine On
# Check if this is the noredirect query string
RewriteCond %{QUERY_STRING} (^|&)noredirect=true(&|$)
# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]
# Check if this looks like a mobile device
# (You could add another [OR] to the second one and add in what you
# had to check, but I believe most mobile devices should send at
# least one of these headers)
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile} !^$
# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST} !^m\.
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP:Cookie} !\smredir=0(;|$)
# Now redirect to the mobile site
RewriteRule ^(.*)$ mobile/$1 [R,L]
信用额必须为原始答案 - 使用htaccess的移动重定向
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.