我有一家网店,由于谷歌决定推广网页的移动版本,我正在开发我的m.example.com
。
这是诀窍。我不想要,m.
域名。我想要的是,当用户来的时候,我检查用户代理,如果它来自移动,我会显示移动版本,如果来自桌面,则显示桌面版本。
但是,我想对用户使用完全相同的网址。因此,http://example.com/contact/
将成为桌面用户和两个移动用户的网址。
该页面的移动版本位于子目录./mobile/
。
是否可能以某种方式强制apache,更改文档根目录,如果有人来自移动设备,但保留原始URL?
例如:
http://example.com/contact/
应运行/var/apache/example.com/mobile/contact.php
,但对于桌面版,应运行/var/apache/example.com/contact.php
?正如我所提到的,URL是相同的。
如果问题不明确,请发表评论。
答案 0 :(得分:0)
这样的东西? (从this answer整理,然后只进行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]
)
{{1}}
信用必须转到原来的答案 - Mobile Redirect using htaccess