blarg?

Whoops.

I’ve moved everything over to PHP, so all my archive files now end with .php instead of .html, which basically means that anyone who’s ever linked to anything I’ve written just got cut off.

This seems uncivilized, so I though I should do something about it, but my first attempt to fix it with a bash script that made symlinks not only didn’t work and it was obvious that even if it did work it would be an awfully ugly way of doing things. So I undid that, because I there just has to be a less-gross way of doing that kind of thing, right?

Yup.

Having read up on Apache’s URL rewrite module, an underpublicized power-tool of webspace administration, not only have I fixed it, but it will require zero maintenance from me in the future and, best of all, nobody should notice that I’ve even made the switch.


RewriteEngine on
RewriteBase /~mhoye/blarg/archives
RewriteRule (.*)\.html $1.php

Small victories, small victories.

3 Comments | Skip to comment form

  1. Mike

    This technique can also be used to great effect when you want to give people friendly URLs for copy and paste, but are using something like a PHP or JSP backend to generate the page content.

    My friend’s company, RadiantCore uses it so that users can’t see/tell that all of the content on the pages that they’re viewing are generated by JSPs … a request for “radiantcore.com/news/62″ is instantly rewritten as “radiantcore.com/news.jsp?article=62″ or whatever.

  2. Rob

    That seems like a lot of work that ends up just creating a duplicate, extraneous namespace.

    You could have just told Apache something like

    SetOutputFilter PHP
    SetInputFilter PHP
    LimitRequestBody 524288

    Personally, I try to avoid linking to files at all. Usually just to a directory, which has an index.whatever file, because I change extensions all the time.

    It’s also possible to tell apache that http://server/directory/script/arg/arg/arg get passed as $0=/var/www/html/directory/script/index.cgi $1=arg/arg/arg — which I don’t remember exactly how to do off hand, but it’s been very, very good to me in the past. I used it to build a streaming MP3 jukebox once with just one bash script on the server to autogen the playlists on the fly and such, but I now use the DirectoryIndex for that.

    Just another example of what I see as long-term best practices in keeping URL namespaces and directory cluttering to a minimum.

  3. Anonymous

    That seems like a lot of work that ends up just creating a duplicate, extraneous namespace.

    You could have just told Apache something like

    <Files *.html>
    SetOutputFilter PHP
    SetInputFilter PHP
    LimitRequestBody 524288
    </Files>
    

    Personally, I try to avoid linking to files at all. Usually just to a directory, which has an index.whatever file, because I change extensions all the time.

    It’s also possible to tell apache that http://server/directory/script/arg/arg/arg get passed as $0=/var/www/html/directory/script/index.cgi $1=arg/arg/arg — which I don’t remember exactly how to do off hand, but it’s been very, very good to me in the past. I used it to build a streaming MP3 jukebox once with just one bash script on the server to autogen the playlists on the fly and such, but I now use the DirectoryIndex for that.

    Just another example of what I see as long-term best practices in keeping URL namespaces and directory cluttering to a minimum.