Serving a file with no extension as text/html

I have been unable to read the archives of the blog of my friend Kassie, because firefox doesn’t render those pages as html. I gave her some advice to fix it, but, uh, I didn’t want to write pages and pages of explanation because… uh… well, that’s complicated, but regular readers can probably put that all together. However, she linked to me, so I guess she doesn’t think that I’m too much of an asshole. As such, I’ll present the longer explanation, and it will be a nice lesson for even some of my web-savvy friends (who have been instructed to punch me in the nuts for doing this).

Okay, so if you have a page like this:
http://www.kassiechurch.net//archives/2005_08_01_archive
where the file does not end in an extension like .htm, the server will tell the browser that the content-type is “text/plain” and some browsers will display it as plain text — especially firefox.

Too complicated? Well, let’s imagine a conversation between firefox and a web server, initiated when a user clicks a link on a page that takes them to an archive page.

firefox: Hey.
server: Hey.
firefox: Sooooo…
server: Yeah. Uh, how have you been?
firefox: Good. Good. I mean, school is going good. You know, classes and stuff. How are you?
server: Not bad, you know, working, married, whew.
firefox: Oh yeah, congratulations. I never said anything.
server: That’s, okay, uh, sorry for not inviting you. I guess after you didn’t respond to the engagement announcement we just thought that you didn’t like us.
firefox: Oh, yeah, sorry. I was in a weird place and guess I didn’t know if I did like you anymore. I didn’t like much of anything.
server: Yeah. You were kind of an ass.
firefox: Ha. Yeah, I deserve that. Aaaaanyway, I was wondering if you have that file I was looking for. Uh, /archives/2005_08_01_archive. No big deal, I was just kind of looking for it.
server: Oh yeah, that’s down in the basement. Here you go. Oh, there’s no .htm on that anywhere, so I guess it’s text/plain.
firefox: I guess so. Thanks. See ya later.
server: See ya.

So there you have it. I bet that you had no idea that firefox and the server used to be roommates. I think that firefox just fakes being nice so that his stuff doesn’t get thrown into a dumpster when he isn’t looking.

Anyway, so there are a few ways that the server could know that the files in archives are text/html. They could be renamed with an appropriate extension, like
/archives/2005_08_01_archive.htm

Another way would be to modify the server’s configuration to say that things are text/html if it doesn’t have an extension. Assuming that the server is running apache, one could edit the server config and restart it. This is probably not an option for Kassie, because she very likely is not root on her server. A slightly easier way would be to try creating a file called .htaccess and putting the configuration option into it. That file would live in her document root so that it would affect the archives/ folder and the folders that are organized by year (for the links from rss). That file would need only one line in it:
DefaultType text/html

Of course, the server would have to already be configured to allow that parameter to be overridden on a directory by directory basis. She might be out of luck. Additionally, it is sometimes non-trivial to create a file called .htaccess. The leading dot makes most graphical operating systems grumpy. Personally I would just ssh into her box and try using emacs or nano or (shudder) vim. If, after successfully getting an .htaccess file onto the server she just gets a big “500 server error,” then she is not allowed to have .htaccess files, or she made a mistake in that one line. Make sure there’s a return character at the end.

To me, a better solution would be to change the templates that blogger uses when it publishes. Go to “basic settings” and then “archive settings.” Put either an .htm or .html extension on the end of the “Archive Filename” field. Republish everything. Hopefully that’s where the magic happens and all of your pages and links are regenerated with extensions. I couldn’t find any way to edit the filenames of the individual posts, so I’m hoping that setting gets carried over.

“But Jesse,” you might ask. “Why do your blog posts have totally awesome urls, and yet everyone can read them in any browser? Why do you get to be so awesome?”

I tell you why: I am the magic man.

Okay, I use an apache module called mod_rewrite, which takes the url that the server is given and does some shenanigans with it, so
http://jpmullan.com/blog/date/2005/08/04/
becomes
http://jpmullan.com/blog/index.php?year=2005&monthnum=08&day=04
which isn’t as pretty. Actually, that gets translated again into something else still, but that’s a longer story.

I can’t help it, I have to help people when they ask.

5 Responses to “Serving a file with no extension as text/html ”

  1. you could have explained that to me in like 2 sentences (even though i’m dumb), but it would have lost all the hilarity with the conversation and all the awesomeness that is Jesse.

  2. Okay, here’s the deal, while I don’t understand 99% of what you are saying, the one thing I do understand is the “put an .htm on the end” part. Unfortunately, I have no idea where that would go. I guess I’m just stupid. The deal is, I have two blogs. One has archives that work, one doesn’t. They seem to be coded the same. Here’s the code:

    [code deleted by jesse]

    Where does the .htm go?

  3. ooh, most of the code seems to have gone away when I posted this. I will email it.

  4. Email received and replied to.

  5. Lisa’s comments were deleted because I don’t want to be that publicly and directly mean. Sorry.

RSS

People I Know

Random Stuff

26 queries. 0.066 seconds.

Technorati Profile