views:

32

answers:

2

I'm treating all *.jpg files as static, but I need to serve a few dynamically. Can I simply omit the extension so I don't have to get fancy with my url rules? Is it enough to just set the file type in the header?

A: 

Instead of omitting the extension (on your server), activate content negotiation (i.e. +MultiViews if you're using Apache) and omit the extensions in your URIs. That way, Apache will decide what file to serve; you could have an image in both png and svg format, and serve the one accepted by the browser.

Generally, a correct Content-type header is enough.

You
+1  A: 

I've never had a problem serving dynamic images with a strange extension or no extension at all. Querystrings are also fine.

It will be enough for the headers to be correct and the binary file correctly formed. When you do this make sure you also set the Content-Disposition to a reasonable file name so people don't try to download your files with crazy querystring names. (Which windows users will be unable to save since they will most likely have a "?" in them.)

jwsample