.htaccess ForceType unnecessary for images?
am 25.08.2007 01:17:49 von Lawrence SanI was reading in the Apache 1.3 docs and elsewhere about .htaccess
ForceType, which lets you specify all the files in a given directory as
being of a certain type (like HTML, or GIF, or whatever) without having
to use a dot extension on the URL. A page I read at the W3C actually
recommended constructing URIs this way (with no dot extension) but
keeping the dot extension on the files themselves; other things I've
seen suggested even that wasn't necessary.
Curious about this, I constructed a simple HTML file containing an img
tag pointing to a JPEG. I named the JPEG file simply "01" and specified
it in the HTML page using . This was just a baseline test;
since I hadn't entered ForceType (or any other content descriptor) in
the directory's .htaccess file, I assumed the graphic would fail to load.
To my amazement, it loaded fine in every browser I tried: Mac Firefox
and Safari, Windows IE6 and even Windows IE5.01.
I assume the browsers guessed it was an image because it was in an img
tag, but even so, how did the browser know to render it as a JPEG, and
not a GIF or PNG -- or as text, since that's apparently what Apache sent
it as? (From Mac Firefox 2, the http request header said "Accept
image/png,*/*;q=0.5", and from Apache 1.3.37 on FreeBSD, the http
response header said "Content-Type text/plain".)
Does this mean ForceType (or other content negotiation, MIME stuff,
etc.) is unnecessary for images? You can just omit the dot extension
both from the files and URLs, and don't need to put anything special in
the .htaccess files?
--
Lawrence San
Cartoon Stories for Thoughtful People: