Redirect internal to path, if resource doesn't exists

馋奶兔 提交于 2020-01-03 03:39:12

问题


i am trying to redirect internally to another location, so the user won't see the "script" location / uri, if an image does not exists:

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

For example if i request an image:

http://domain.tld/resources/img/tires/manufacturer/image.jpg -> Image exists, directly serve the image.

And if i request:

http://domain.tld/resources/img/tires/manufacturerX/image2.jpg -> Image does not exist, call the script which is located at http://domain.tld/reifen/imagematch/{manufacturerX/image2.jpg}

What do i have to modify in my rewrite rules, so that the shown example will work correctly?

Best regards and thanks!


回答1:


You can use this rule in root .htaccess:

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


来源:https://stackoverflow.com/questions/22300461/redirect-internal-to-path-if-resource-doesnt-exists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!