Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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
Regex 如果图像不';不存在_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Regex 如果图像不';不存在

Regex 如果图像不';不存在,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我已设置此规则,以便处理未找到的图像 RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteRule ^files/([a-zA-Z0-9]+)/([^.]*).(gif|jpe?g|png|bmp) /open/img/404/$1.jpg [NC,L] 因此,如果url是/files/offers/this/that/other/file.jpg,并且图像不存在,它将显示图像/open/img/404/offers.jpg。这非常有效,

我已设置此规则,以便处理未找到的图像

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^files/([a-zA-Z0-9]+)/([^.]*).(gif|jpe?g|png|bmp) /open/img/404/$1.jpg [NC,L]
因此,如果url是
/files/offers/this/that/other/file.jpg
,并且图像不存在,它将显示图像
/open/img/404/offers.jpg
。这非常有效,除非
提供.jpg
不存在,否则它会抛出500内部服务器错误


是否可以使规则仅返回
/open/img/404/something.jpg
图像(如果存在),如果不返回
/open/img/404/defaultImage.jpg

是的,可以有如下规则:

# if /open/img/404/$1.jpg exists
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}/open/img/404/$1.jpg -f
RewriteRule ^files/([a-zA-Z0-9]+)/([^.]+)\.(gif|jpe?g|png|bmp) /open/img/404/$1.jpg [NC,L]

# if /open/img/404/$1.jpg doesn't exist
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}/open/img/404/$1.jpg !-f
RewriteRule ^files/([a-zA-Z0-9]+)/([^.]+)\.(gif|jpe?g|png|bmp) /open/img/404/defaultImage.jpg [NC,L]

谢谢:),效果很好。只是好奇,在第二和第四秒,1美元的参数是从哪里来的?根据下面的规则?是的,这是正确的,
$1
来自
重写规则