Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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
Php .htaccess重写规则500内部服务器错误_Php_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php .htaccess重写规则500内部服务器错误

Php .htaccess重写规则500内部服务器错误,php,regex,apache,.htaccess,mod-rewrite,Php,Regex,Apache,.htaccess,Mod Rewrite,我需要将图像文件重定向到不同的文件夹。我尝试使用: RewriteCond %{HTTP_HOST} ^example.com$ [NC] RewriteCond %{REQUEST_URI} (.*)\.(png|gif|jpg|jpeg) RewriteRule ^(.*)$ images/$1 [L] RewriteCond%{HTTP_HOST}^example.com$[NC] RewriteCond%{REQUEST_URI}(.*)\(png | gif |

我需要将图像文件重定向到不同的文件夹。我尝试使用:

RewriteCond %{HTTP_HOST} ^example.com$ [NC] RewriteCond %{REQUEST_URI} (.*)\.(png|gif|jpg|jpeg) RewriteRule ^(.*)$ images/$1 [L] RewriteCond%{HTTP_HOST}^example.com$[NC] RewriteCond%{REQUEST_URI}(.*)\(png | gif | jpg | jpeg) 重写规则^(.*)$images/$1[L] 这将导致500个内部服务器错误,但以下操作有效:

RewriteCond %{HTTP_HOST} ^example.com$ [NC] RewriteCond %{REQUEST_URI} (.*)\.(png|gif|jpg|jpeg) RewriteRule ^(media/1.jpg)$ images/$1 [L] RewriteCond%{HTTP_HOST}^example.com$[NC] RewriteCond%{REQUEST_URI}(.*)\(png | gif | jpg | jpeg) 重写规则^(media/1.jpg)$images/$1[L] 这也适用于:

RewriteCond %{HTTP_HOST} ^example.com$ [NC] RewriteCond %{REQUEST_URI} (.*)\.(png|gif|jpg|jpeg) RewriteRule ^(.*)$ images/media/1.jpg [L] RewriteCond%{HTTP_HOST}^example.com$[NC] RewriteCond%{REQUEST_URI}(.*)\(png | gif | jpg | jpeg) 重写规则^(.*)$images/media/1.jpg[L]
我不明白为什么会发生这种情况,有什么帮助吗?

由于循环,您将收到500个错误。Apache一直使用
mod_rewrite
模块运行重写的URI,直到它们无法匹配任何规则

使用更好的检查尝试此规则:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{REQUEST_URI} !/images/ [NC]
RewriteRule \.(png|gif|jpe?g)$ images%{REQUEST_URI} [L,NC]
这将仅在URI中不存在
/images/
时重写图像URL