Apache's DirectoryIndex directive tells Apache to look for, e.g. index.html
and index.php
if the client requests a directory.
Is there some easy way to get Apache to analogously look for e.g. /$filename.jpg
if the client requests /$filename
?
For example, if the client requested /foo
, then Apache might be configure to look for /foo.jpg
and /foo.png
on disk, and return a 404 if neither of these files exist. (I am aware that it's possible to use mod_rewrite
for this, however I would like a simple (and more performant) solution.)
Sounds like you want to use
Options Multiviews
for this; documentation is here.You could probably use mod_speling for that purpose but you'll run into problems if you have several documents with "similar" names in the document root.
I'd prefer the solution with mod_rewrite over mod_speling.
Do a single redirect non-existing-files to index.php, find the potential files and return it with PHP instead.