2

Hey there StackOverflow Community, i searched a lot on stackoverflow to fix my "too many redirect" Error. But couldn't find anything that helps. I want to redirect to a mobile directory via .htaccess and the UserAgent Condition. Found a high voted Solution that looks like this:

RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|ipad|iemobile" [NC]
RewriteRule ^(.*)$ http://mysite.com/mobile/$1 [R=301,L]

The redirect itself works great but its seems like the mobile browsers add /mobile in a loop so the URL grows into something like http://mysite.com/mobile/mobile/mobile/mobile/mobile/mobile/mobile/mobile till i get an Error "couldn't open site because of too many redirects".

My complete .htaccess looks like this:

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]

Thanks in Advance, Lucas Tito

4

1 回答 1

2

用这个替换你RewriteRule的:

RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|ipad|iemobile" [NC]
RewriteRule ^((?!mobile/).*)$ /mobile/$1 [R=301,L]

问题是您无条件地/mobile/在任何 URL 之前添加前缀,即使是已经以/mobile/.

于 2013-09-25T15:58:17.050 回答