0

I'm using some default images to show users the type of document that is used.

e.g. this image to show there is a .png file

e.g. this image to show there is a .png file

In the /osr/icons/mime/ folder I have images for a multitude of files, e.g. avi.png, html.png, jpg.png, ...

So I simply need to get the file extension for my current document, for example png and display /osr/icons/mime/png.png

In case there is a file-format I don't have a predefined image, I'm using a rewrite condition to automatically show a generic image.

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} /osr/icons/mime/(.*).(gif|jpg|jpeg|png)$
RewriteRule ^(.*) /osr/icons/mime/generic.png

This works fine, except if the extension of a document is uppercase, e.g. .PNG instead of .png. In this case my code tries to display /osr/icons/mime/PNG.png which does not exist, an therefore shows the generic image.

Is there a way to change the RewriteCond/Rule to fallback to the lowercase image?

I found How do I do a case-insensitive mod_rewrite redirect to the same URL (mod case)? which recommends RewriteMap insensitive tolower: but I don't exactly know if/how this would work for me. Using [NC] didn't work either.

I know of the following work-arounds, which I don't really want to use:

  • Switching to case-insensitiv file handling for the folder
  • Dublicating List item all files in the folder to uppercase names (would not take .Png into account)
  • Rewriting the code that loads the image file to automatically use lowercase
Pit
  • 121
  • 5
  • Why not simply get rid of (gif|jpg|jpeg|png) and match any file in /osr/icons/mime/ that doesn't exist? – Fira Mar 09 '16 at 09:16
  • My question is not about the non-existing files, but about those that exists, but with a different case. How do I get to display the lowercase file for upper- or mixedcase extensions – Pit Mar 09 '16 at 09:22
  • That's what i mean. If you remove the match condition on the extension, it'll simply match any file that doesn't exist. That does the job very well if all you have in that directory is images. – Fira Mar 09 '16 at 09:29
  • Okay, nevermind, i see what you mean, the problem is with !-f... – Fira Mar 09 '16 at 09:34

0 Answers0