问题
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