Permalink Progress

After reading the helpful entry Redirection Complete over at Stopdesign, I decided to try and help my old permalinks find their way to at least the correct monthly archive page.

Reading up a little on regular expressions helped me write this solution to my .htaccess file:

RewriteEngine	on
RewriteBase	/
RewriteRule	^2003([0-9][0-9])	archives/2003/$1/	[R]

There’s a similar RewriteRule for each year of archives. So now any old-style permalink pointing to something like /YYYYMM#123456789 will redirect to /archives/YYYY/MM/ which is that month’s archive. Not perfect yet, but at least a heck of a lot better.

There are also some additional links to helpful MT link conversion methods in the comments to the previous post — for those having to deal with the same scenario.

7 Comments

  1. Jasmeet says:

    I kinda miss the old full posts feed that you had before too. Will you ever bring them back?

  2. Benvolio says:

    Hey there Dan,
    I was wondering why I could never post comments before this… now I know.
    AM looking forward to even more innovations now you’ve moved to MT.
    How are getting your archives to output to a name_of_entry.html?
    Benvolio

  3. Dan says:

    Jasmeet – I might bring that back, just need to play around with the RSS templates, making sure I handle HTML in the best way possible.
    Benvolio – good question on the entry title naming. There’s an attribute in MT called “dirify” that will change to lowercase, strip out odd characters and add in underscores between words. If you add a custom Archive File Template for your Individual Archives (under Weblog Config / Archiving) that looks something like this: <$MTArchiveDate format=”%Y/%m/%d/”$><$MTEntryTitle dirify=”1″$>.html — all the work is done for you.
    I figure it’s a good idea to archive by day using this method — in case you have a post using the same title within the same month.

  4. Jim Ray says:

    When I switched how my MT install archived entries, I had MT build an .htaccess file for me. Hope it helps
    http://www.quietconfusion.com/2003/03/movable_type_file_rewrite.php

  5. Sunny says:

    I am sorry for the previous two comments. For some reason the “option>paste” is playing games with me. (Please delete the previous comments)
    For full posts, use: <$MTEntryBody encode_xml=”1″ remove_html=”1″$>
    I am sure you prolly figured this out, but just in case.

  6. Maurice says:

    You shouldn’t need one for each year. This is still very conservative (and untested):
    RewriteRule ^(1999|2001|2002|2003)([0-9][0-9]) archives/$1/$2/ [R,L]
    Or maybe just:
    RewriteRule ^([0-9][0-9][0-9][0-9])([0-9][0-9])
    archives/$1/$2/ [R,L]

  7. Dan says:

    Maurice – brilliant! Works like a charm. Much better, thanks.
    Sunny – yup, found out that’s the way, but just not sure about stripping out HTML — sometimes posts depend on it for code examples, etc. Whether or not to use CDATA is a question…