我想創建一個移動Safari版本的瀏覽器嗅探器,問題是重定向創建一個無限循環,顯然,我想知道是否有辦法做到這一點:帶有mod_rewrite和重定向的iPad/iPhone瀏覽器嗅探器; 「太多的重定向」
http://mydomain.com(或任何其他requets_uri)[301] - >http://mydomain.com/ipad
下面是我使用的代碼片段:
RewriteCond %{REQUEST_URI} !^ipad #Trying to set the condition "if /ipad is not the request_uri, but it doesn't work
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^(.*)$ ipad [R=301,L]
更新:這是我的(修改)全套mod_rewrite的規則:
RewriteEngine On RewriteBase/
# iOS redirection.
RewriteCond %{REQUEST_URI} !^/ipad
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^(.*)$ /ipad [R=301,L]
# If the requested URL does not exist (it's likely an agavi route),
# pass it as path info to index.php, the Agavi dispatch script.
RewriteRule ^$ index.php?/ [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/favicon.ico
RewriteRule (.*) index.php?/$1 [QSA,L]
更新2:FINAL;感謝的答覆,我是來這我張貼任何人有同樣的問題的一個解決方案:
RewriteEngine On
RewriteBase/
# iOS redirection.
# Make sure the URL hasn't already been rewritten internally
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteCond %{REQUEST_URI} !^/ios
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/favicon.ico
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^.*$ /ios [R,L]
# If the requested URL does not exist (it's likely an agavi route),
# pass it as path info to index.php, the Agavi dispatch script.
RewriteRule ^$ index.php?/ [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/favicon.ico
RewriteRule (.*) index.php?/$1 [QSA,L]
太棒了!謝謝你幫助Tim,非常感謝:) – lmerino 2011-02-27 16:48:35