fettig.net

An improved 404 handler

Posted by Abe on Thursday, February 6, 2003 @ 9:20 am

Les Orchard is thinking about moving from Moveable type to Pyblosxom.  "I’ll just have to work out some way to redirect requests for ‘old’ URLs to the new content", he says.  Which reminds me that a while ago I made some changes to my own 404 handler, and forgot to mention it here.


The improved 404 handler reads a tab-delimited file called moved.txt.  The file has two columns - old file location, new file location.  Requests for the old file will be redirected to the new one.  The cool thing is that both old and new file can be regular expressions, so if you change the format of your archive pages from /archives/year_mo.html to /archives/year/mo/, you can just add a line to moved.txt like this:


/archives/(….)_(..)\.html    /archives/\1/\2


The code is here: http://www.fettig.net/files/404-2.py.

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.