Forum Moderators: phranque

Message Too Old, No Replies

AddType for extensionless file

Using AddType to set type of file with no extension

         

cfoster

10:44 pm on Feb 7, 2005 (gmt 0)

10+ Year Member



Is it possible to set the mime type for a file with no extension?

I don't want to change the DefaultType, as I like setting this to 'application/octet-stream' (so all unknown files will be downloaded, not loaded into the browser window as HTML).

I'd also prefer not to bother with the rewrite engine for a couple of reasons.

AddType would be perfect, except I can't figure out a syntax that means 'no extension'.

Does anyone have any ideas?

(My goal is to have files without extensions be interpretted as php files.)

Thanks!
-Colin.

jdMorgan

11:40 pm on Feb 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Colin,

Welcome to WebmasterWorld!

The right way to do this is name the files as .php, and then rewrite the URLs that have no extension to those filenames using mod_rewrite. AddType is not going to work, because there is no type. This is precisely what mod_rewrite does, it translates URLs to filenames in other than the default way.

If you don't want to do that, and you can stand a big slow-down in your server, then look into content-negotiation using MultiViews. This can cause other problems as well, though, because of the way it works.

Jim

cfoster

12:32 am on Feb 8, 2005 (gmt 0)

10+ Year Member



Hey Jim,

Thanks for the Welcome, and thanks for the tips!

I wasn't too keen on rewrite since it seemed like I'd be adding a bit of overhead (although minute) to every single transaction.

I also tried 'Location/ForceType', specifying a path to the file, but to no avail. Hmmm... maybe I'll just go back to changing the DefaultType.

I had also been thinking about using an unclaimed extension such as '.web' and then using AddType to specify its kind. (So as far as the user knows, page.web could be ASP, PHP, HTML, etc.)

-Colin.