0

I used the following rule to check if the png exists.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!.+/default\.png$).+\.png$ /web/team/default.png [L,NC,R=301]

If it does not it will redirect to default.png

The rule now redirects all pngs in my website to this default.png even if the png file is exists.

I want to re-produce the rule to be applied if the request url has the following pattern

host + /web/images/team/anyimagehere.png  

If this png does not exist then fire the rule to redirect

Note that this path /web/images/team/ does not exist in the file system. It's based on the application so will only be generated by the application on request.

Any advise here how to adjust this rule?

Bananaapple
  • 2,984
  • 2
  • 25
  • 38
Jecki
  • 802
  • 3
  • 16
  • 32

1 Answers1

0

If I correctly understand what you are trying to achieve you can do that like so:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^web/images/team/(.+)\.png /web/team/default.png [L,NC,R=301]

Demo here: http://htaccess.mwl.be?share=669f961b-d3c8-55e1-af32-bced3a260e73

Bananaapple
  • 2,984
  • 2
  • 25
  • 38
  • the logic is correct but i still can see 500 error from the application when i request the file which is not exist curl -I http://hosthere/web/images/team/555.png HTTP/1.1 500 Internal Server Error Date: Thu, 14 Sep 2017 09:05:57 GMT – Jecki Sep 14 '17 at 09:10