scriptygoddess

25 Feb, 2003

Archive Redirects made (more) simple

Posted by: adam In: MT hacks

A few weeks ago, Kristine posted about Redirects in MT, and this got me thinking. I had already looked at an archive mapping solution which was recently updated, but it required that I have access to the server config files (not just a .htaccess file) because a RewriteMap can only be defined in the server config files.

So tonight when I decided, after a great deal of pondering (about 10 minutes), to change my archiving format to something that didn't produce 1000+ numerically named directories I needed a way to map the archive numbers to their new named location. Here is the solution I came up with, based on some modifications of the pre-existing code.

First download mt-archivefinder.cgi and rename it to mt-archivefinder.cgi (or any other name that suits your purposes). Put it in the MT directory.

You will need to change a couple of the lines at the top of the file to match your server's configuration. Make sure to chmod the file 755.

Next you will need to do some mod_rewrite mojo with a .htaccess file. Create a .htaccess file or edit the existing file in the root of your archives directory. To that file add:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/archive/[0-9]{6}.html
RewriteRule ^(.*).html$ /mt/mt-archivefinder.cgi?$1

You will need to change it to reflect your path structure. If all goes well, you will be automagically redirected from any numbered file like /archives/000001.html to whatever new archiving scheme you enter into the individual archive template in the Weblog Config panel in MT.

For example, I was using

<$MTEntryID pad="1">/index.php

and now I'm using

<$MTArchiveDate format="%Y"$>/<$MTArchiveDate format="%m"$>/<$MTEntryTitle dirify="1"$>/index.php

I used the following mod_rewrite rule to automatically forward all links to the old archive style to the new archive style.

RewriteCond %{REQUEST_URI} ^/history/[0-9]{6}/
RewriteRule ^(.*)/$ /mt/mt-archivefinder.cgi?$1

That's all it takes!

Many thanks to Alex for the inspiration and the code.

3 Responses to "Archive Redirects made (more) simple"

1 | Shelagh

February 27th, 2003 at 3:39 am

Avatar

I might be missing the point here but why not just change the blog config? I have mine set up so that in the archives there is a dir for each year, they have further subdirs for each month. Within each month the monthly archive is the index and the individual archives are numbered. I use this format-
Individual archives:
<$MTEntryDate format="%Y/%m/"$><$MTEntryID pad="1"$>.php
Monthly archives:
<$MTArchiveDate format="%Y/%m/index.php"$>

2 | adam

February 27th, 2003 at 3:48 am

Avatar

Well, I changed my blog config, but I wanted people's links to my archives to continue to resolve to the new location. For example, Rannie has linked to http://www.gessaman.com/history/001068/ which was the old location of my flip gallery script. When I updated my archiving scheme to something that I found more useful, I didn't want to IM him simply to have him update the link. I also didn't want to wait for every search engine on the planet to realize that my archives had moved before I deleted the old output files. That's where this script comes in. It changes old 001068.html archives to point to wherever entry number 1068 has ended up no matter how many times I change my archives. In this case, it ended up here.

Of course, I can't change my archives again without re-writing the script to do look-ups by archive name. *grin*

3 | unsquare/dance

March 30th, 2005 at 1:24 am

Avatar

Updated and Upgraded
Today I decided on a whim that I wanted to upgrade my version of Movable Type to the newest, brand-spankin'-est one available, so I downloaded the goods and did all the standard upgrading. However, I also decided that I no…

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements