2012-12-27 52 views
2

我正在處理小型CMS,我通過RewriteRulehtaccess中將所有原始目錄更改爲我需要的目錄,還爲移動設備用戶添加移動模板。所以我的網站有兩個目錄,一個用於計算機客戶端,一個用於移動客戶端,我使用以下代碼來檢測手機代理並重定向到手機模板,但會出現循環錯誤,任何想法!?移動重定向和循環錯誤

這是我的重定向代碼:

RewriteCond %{REQUEST_URI} !^/m/.*$ 
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC] 
RewriteRule ^(.*)$ /m/ [L,R=302] 

這是我目前的htaccess:

Options +FollowSymLinks 
RewriteEngine On 
# Change main URL 
RewriteRule ^m/ /mobile/index.php [QSA] 
# Change content URL 
RewriteRule ^/a/m/([a-zA-Z0-9\.]+)$ /mobile/index.php?pid=$1 [QSA] 
+0

試圖從條件的RewriteCond%去掉斜線{REQUEST_URI}^M /.*$ – vmeln

+0

@ V.Melnychuk我試過但沒有工作! – NullPointer

回答

1

您需要檢查的URI也不是重寫的URI(/mobile/...)。你可以做到這一點無論是覈對%{THE_REQUEST}或包括/mobile檢查:

RewriteCond %{THE_REQUEST} !\ /m/.* 
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC] 
RewriteRule ^(.*)$ /m/ [L,R=302] 

或:

RewriteCond %{REQUEST_URI} !^/a/m/.*$ 
RewriteCond %{REQUEST_URI} !^/m/.*$ 
RewriteCond %{REQUEST_URI} !^/mobile/.*$ 
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC] 
RewriteRule ^(.*)$ /m/ [L,R=302] 
+0

@AliGhanei這是因爲相對URI基礎已經改變了(從'/'用'/ mobile'改成'/ m /'或'/ a/m /')。您需要使用絕對URL或在頁面的標題中包含一個'。 –

+0

你的第一個代碼完美的工作,但禁用其他鏈接:-( – NullPointer

+0

爲什麼這段代碼阻止我的其他鏈接,而我使用絕對url? – NullPointer