0

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.)

ithinkihaveacat
  • 1,604
  • 3
  • 14
  • 18

3 Answers3

2

Sounds like you want to use Options Multiviews for this; documentation is here.

nickgrim
  • 4,336
  • 1
  • 17
  • 27
1

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.

joschi
  • 20,747
  • 3
  • 46
  • 50
0

Do a single redirect non-existing-files to index.php, find the potential files and return it with PHP instead.

Mark
  • 740
  • 5
  • 5
  • A valid solution, although this is probably much slower than just using mod_rewrite for that purpose. At least with a fixed list of file extensions to check. – joschi Mar 06 '11 at 18:47
  • Absolutely, it does however answer the question raised and as far as simple goes, there's likely already code for this exact "issue" on the internet :) – Mark Mar 06 '11 at 18:55