Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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

share|improve this answer

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.

share|improve this answer

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

share|improve this answer
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 6 '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 6 '11 at 18:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.