2012-12-28 29 views
0

我想設置我的網站重定向到移動版本使用.htaccess。 我的主要目的是重定向來自手機的所有請求,除了直接請求圖像文件的請求。圖像文件位於三個文件夾的根文件夾下:/ IMG//文件//userfiles/REQUEST_URI否定不在重定向

我使用的是下面:

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

重定向正在發生的來自移動設備沒有所有的請求檢查文件夾條件。

如果我嘗試訪問www.normalsite.com/img/somefile.jpg,它仍然會將我重定向到mobilesite.com,即使上面的條件會阻止它這樣做。

有人可以幫忙嗎?

謝謝。

回答

1

應該是這樣的:

# Assume this condition works. 
RewriteCond %{HTTP_USER_AGENT} "(android|blackberry|googlebot-mobile|iemobile|iphone|ipad|ipod|opera mobile|palmos|webos)" [NC] 

# Modified conditions 
RewriteCond %{REQUEST_URI} !/files.* [NC] 
RewriteCond %{REQUEST_URI} ![\.(jpg|png|jpeg|gif)].* [NC] 
RewriteCond %{REQUEST_URI} !/userfiles.* [NC] 
RewriteRule ^(.*)$ http://mobilesite.com/$1 [L,R=302] 

添加其他圖片擴展這裏如果必要的話:

RewriteCond %{REQUEST_URI} ![\.(jpg|png|jpeg|gif)].* [NC]

+0

所以你改變的RewriteCond%{REQUEST_URI}^/文件/(.*) [NC]改寫爲%{REQUEST_URI}!/文件。[NC] - 這不是一個改進,是嗎? – Gerfried