簡體   English   中英

移動版本的文檔根目錄(.htaccess?)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM