0

我正在尝试将我的网站设置为使用 .htaccess 重定向到移动版本。我的主要目的是重定向来自移动设备的所有请求,但直接搜索图像文件的请求除外。图像文件位于根文件夹下的三个文件夹中: /img/ /files/ /userfiles/

我正在使用以下内容:

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,即使上述条件应该阻止它这样做。

有人可以帮忙吗?

谢谢你。

4

1 回答 1

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]

于 2012-12-28T20:15:42.193 回答