Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 请求\u URI否定不适用于重定向_.htaccess_Redirect_Web - Fatal编程技术网

.htaccess 请求\u URI否定不适用于重定向

.htaccess 请求\u URI否定不适用于重定向,.htaccess,redirect,web,.htaccess,Redirect,Web,我正在尝试使用.htaccess设置我的网站以重定向到移动版本。 我的主要意图是重定向所有来自移动设备的请求,除了直接查找图像文件的请求。图像文件位于根文件夹:/img//files//userfiles下的三个文件夹中/ 我正在使用以下工具: RewriteCond %{HTTP_USER_AGENT} "(android|blackberry|googlebot-mobile|iemobile|iphone|ipad|ipod|opera mobile|palmos|webos)" [NC]

我正在尝试使用.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,尽管上述情况应该会阻止它这样做

有人能帮忙吗


谢谢。

应该是这样的:

# 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\u URI}![\.(jpg | png | jpeg | gif)].[NC]

所以您更改了RewriteCond%{REQUEST\u URI}^/文件/(.*)[NC]重写COND%{REQUEST_URI}/文件。*[NC]-这不是一个改进,是吗?