2017-01-26 60 views
1

我在其中一個網站上遇到了一些問題.htaccess文件。htaccess - 嘗試重定向到移動網站時出現問題(在子域上)

我得到的錯誤是我試圖重定向太多次。

它目前的工作方式是我需要重定向URL到子文件夾/dist每次我在桌面上,如果我在手機上,我需要去的網站的移動版本,而不是開始mobile.

我htaccess文件的子域看起來是這樣的:

RewriteEngine on 
RewriteBase/

# Check if this is the noredirect query string 
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$) 

# Set a cookie, and skip the next rule 
RewriteRule^- [CO=mredir:0:www.mywebsite.com/dist] 

RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [OR] 
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com$ 
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ 
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ 
RewriteRule ^/?$ "http\:\/\/www\.mywebsite\.com\/dist" [R=301,L] 

# Check if we're not already on the mobile site 
RewriteCond %{HTTP_HOST}   !^m\. 

# Can not read and write cookie in the same request, must duplicate condition 
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) 

# Check to make sure we haven't set the cookie before 
RewriteCond %{HTTP_COOKIE}  !^.*mredir=0.*$ [NC] 

# Now redirect to the mobile site 
RewriteRule^http://mobile.mywebsite.com [R,L] 

任何人可以幫助?

這是我的東西這個

感謝

+0

倘使你發佈錯誤消息,以及。 – DmitriD

+0

加載資源失敗:net :: ERR_TOO_MANY_REDIRECTS – Nick

+0

您的移動網站是否以'm.'或'mobile.'開頭? – anubhava

回答

1

像第一次嘗試你可以這樣說:

RewriteEngine on 
RewriteBase/

# Check if this is the noredirect query string 
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)  
# Set a cookie, and skip the next rule 
RewriteRule^- [CO=mredir:0:www.mywebsite.com/dist] 

RewriteCond %{HTTP_HOST} ^(?:www\.)?mywebsite\.com$ [NC] 
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ 
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ 
RewriteRule ^/?$ http://www.mywebsite.com/dist [R=301,L] 

# Check if we're not already on the mobile site 
RewriteCond %{HTTP_HOST} !^(m|mobile)\. [NC]  
# Can not read and write cookie in the same request, must duplicate condition 
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) [NC]  
# Check to make sure we haven't set the cookie before 
RewriteCond %{HTTP_COOKIE} !^.*mredir=0 [NC] 
# check mobile agents 
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|android" [NC] 
# Now redirect to the mobile site 
RewriteRule^http://mobile.mywebsite.com [R=302,NE,L] 
+0

nope,即使我在桌面上,它也會每次重定向到移動版本 – Nick

+0

爲此,您需要檢查用戶代理,並且該問題不存在於您的問題中。 – anubhava

+0

好,根據這個答案,檢查應該適用於移動設備: http://stackoverflow.com/questions/3680463/mobile-redirect-using-htaccess任何想法,爲什麼它不是我的情況? 感謝您的幫助到目前爲止,順便說一句:) – Nick