如果资源不存在,则将内部重定向到path


Redirect internal to path, if resource doesn't exists

我试图内部重定向到另一个位置,所以用户不会看到"脚本"位置/uri,如果图像不存在:

RewriteCond %{REQUEST_URI} ^/resources/img/tires [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^resources/img/tires/(.*)$ reifen/imagematch/$1 [L]

例如,如果我请求一个图像:

http://domain.tld/resources/img/tires/manufacturer/image.jpg ->图像存在,直接服务于图像。

如果我请求:

http://domain.tld/resources/img/tires/manufacturerX/image2.jpg ->图像不存在,调用位于http://domain.tld/reifen/imagematch/{manufacturerX/image2.jpg}

的脚本

我必须修改我的重写规则,使所示的例子将正确工作?

致以最诚挚的问候和感谢!

您可以在root .htaccess中使用此规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^resources/img/tires/(.+)$ /reifen/imagematch/$1 [L,NC]