Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

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

 
discard

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.