嘿那里StackOverflow社区,我在stackoverflow上搜索了很多来修复我的“太多重定向”错误 . 但找不到任何有用的东西 . 我想通过.htaccess和UserAgent条件重定向到移动目录 . 找到一个高投票的解决方案,看起来像这样:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|ipad|iemobile" [NC]
RewriteRule ^(.*)$ http://mysite.com/mobile/$1 [R=301,L]
重定向本身效果很好,但它看起来像移动浏览器在循环中添加/移动,所以URL增长到像http://mysite.com/mobile/mobile/mobile/mobile/mobile/mobile/mobile/mobile,直到我得到一个错误"couldn't open site because of too many redirects" .
我完整的.htaccess看起来像这样:
AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|ipad|iemobile" [NC]
RewriteRule ^(.*)$ http://mysite.com/mobile/$1 [R=301,L]
在此先感谢Lucas Tito
1 回答
将
RewriteRule
替换为:问题是你在任何URL之前无条件地为
/mobile/
添加前缀,甚至是那些已经以/mobile/
开头的URL .