Is it safe to serve an image on the web without an extension?

后端 未结 2 535
甜味超标
甜味超标 2020-12-18 19:48

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

2条回答
  •  醉酒成梦
    2020-12-18 20:26

    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.

提交回复
热议问题