2013-04-12 32 views
0

無法弄清楚爲什麼我的重定向卡在循環中。我在/ mobile目錄中有一些動態移動內容,我只想將移動用戶引導至該目錄的根目錄。我不斷收到帶有「過多的重定向」錯誤mod_rewrite移動重定向循環

RewriteEngine on 
RewriteBase/

RewriteCond %{HTTP_HOST} !^www. 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

#-------------------------------------------------------------------------------# 

RewriteCond %{HTTP:x-wap-profile} !^$ [OR] 
RewriteCond %{HTTP:Profile}  !^$ [OR] 
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC] 
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC] 

RewriteCond %{HTTP_HOST}   !^www.mysite.com/mobile 

RewriteRule ^(.*)$ http://www.mysite.com/mobile [L,R=301] 


#-------------------------------------------------------------------------------# 

<IfModule mod_deflate.c> 
    AddOutputFilterByType DEFLATE text/css text/javascript application/x-javascript application/javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json 
</IfModule> 


# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress 

IndexIgnore */* 
AddType text/html cgi pl 
AddHandler cgi-script cgi pl 
Options +FollowSymLinks 
Options +ExecCGI 

回答

0

此行停止是有問題的:

RewriteCond %{HTTP_HOST} !^www.mysite.com/mobile 

記住%{HTTP_HOST}只匹配主機名部分不是URI。

您應該使用%{REQUEST_URI}匹配網址,而不是像這樣:

RewriteCond %{REQUEST_URI} !^/mobile [NC]