Not a developer? Go to MovableType.com

Documentation

Changing your URLs: Mapping old URLs to new ones

Users wishing to change their URL structure for their blog should approach this process carefully because a change like this without planning may result in:

  • readers being unable to find your content
  • orphaned files on your file server whose content will be stale over time
  • search engines penalizing you for having replicated content on your web site

To mitigate these risks it is often a good idea to provide your web server with a mapping file that will help redirect your readers from your old URL structure to your new one. The following document will provide you with guidance and sample code for how to complete this process.

This guide however will require customization on your part, as every user’s URL structure can be very different from one another.

Creating a URL Mapping File

This describe a process for users of the Apache web server who have the mod_rewrite plugin installed and enabled. The process involves creating an Index Template that iterates over every file in your blog and outputs a RewriteRule to map the old URL to the new URL for each file.

How it works

Instructions

  1. Create an Index Template called “Rewrite Rules”
  2. Set the output file name to rewrite_rules.conf
  3. Cut and paste and then customize the template code below into the index template
  4. Publish the template
  5. In your httpd.conf file or your .htaccess file, include the following text: Include /path/to/your/rewrite_rules.conf`
  6. Restart Apache

When you are satisfied that everything is working, you may delete the template you created in step #1 above. But keep the rewrite_rules.conf file around forever. It will keep all of your old URLs alive forever.

Sample Template

RewriteEngine on

<MTIfArchiveTypeEnabled archive_type="Individual">
<MTArchiveList archive_type="Individual">
RewriteRule ^<mt:FileTemplate format="/%c/%i" />$ <$mt:BlogURL$><mt:FileTemplate format="%-c/%i" /> [L,R]</MTArchiveList>
</MTIfArchiveTypeEnabled>

<MTIfArchiveTypeEnabled archive_type="Monthly">
<MTArchiveList archive_type="Monthly">
RewriteRule ^<mt:FileTemplate format="/%y/%m/%i" />$ <$mt:BlogURL$><mt:FileTemplate format="%-c/%y/%m/%i" /> [L,R]</MTArchiveList>
</MTIfArchiveTypeEnabled>

<MTIfArchiveTypeEnabled archive_type="Category">
<MTTopLevelCategories>
<MTIfNonZero tag="MTCategoryCount">
RewriteRule ^<mt:FileTemplate format="/%c/%i" />$ <$mt:BlogURL$><mt:FileTemplate format="%-c/%i" /> [L,R]</MTArchiveList>
</MTIfNonZero>
</MTTopLevelCategories>
</MTIfArchiveTypeEnabled>

<MTIfArchiveTypeEnabled archive_type="Author">
<MTArchiveList archive_type="Author">
RewriteRule ^<mt:FileTemplate format="/%a/%i" />$ <$mt:BlogURL$><mt:FileTemplate format="%-a/%i" /> [L,R]</MTArchiveList>
</MTIfArchiveTypeEnabled>

<MTIfArchiveTypeEnabled archive_type="Category-Monthly">
<MTArchiveList archive_type="Category-Monthly">
RewriteRule ^<mt:FileTemplate format="/%c/%y/%m/%i" />$ <$mt:BlogURL$><mt:FileTemplate format="%-c/%y/%m/%i" /> [L,R]</MTArchiveList>
</div>
</MTIfArchiveTypeEnabled>

<MTIfArchiveTypeEnabled archive_type="Author-Monthly">
<MTArchiveList archive_type="Author-Monthly">
RewriteRule ^<mt:FileTemplate format="/%a/%y/%m/%i" />$ <$mt:BlogURL$><mt:FileTemplate format="%-a/%y/%m/%i" /> [L,R]</MTArchiveList>
</MTIfArchiveTypeEnabled>

Sample Output

RewriteRule ^/television/2008/02/index.php$ http://www.majordojo.com/television/2008/02/index.php [L,R]
RewriteRule ^/blogging/2008/02/index.php$ http://www.majordojo.com/blogging/2008/02/index.php [L,R]
RewriteRule ^/blogging/2008/01/index.php$ http://www.majordojo.com/blogging/2008/01/index.php [L,R]
RewriteRule ^/current_events/2008/01/index.php$ http://www.majordojo.com/current-events/2008/01/index.php [L,R]
RewriteRule ^/geeky_goodness/2008/01/index.php$ http://www.majordojo.com/geeky-goodness/2008/01/index.php [L,R]
RewriteRule ^/aint_it_cool/2008/01/index.php$ http://www.majordojo.com/aint-it-cool/2008/01/index.php [L,R]
RewriteRule ^/blogging/2008/01/index.php$ http://www.majordojo.com/blogging/2008/01/index.php [L,R]
RewriteRule ^/current_events/2008/01/index.php$ http://www.majordojo.com/current-events/2008/01/index.php [L,R]
RewriteRule ^/television/2008/01/index.php$ http://www.majordojo.com/television/2008/01/index.php [L,R]
RewriteRule ^/its_funny_laugh/2007/12/index.php$ http://www.majordojo.com/its-funny-laugh/2007/12/index.php [L,R]
RewriteRule ^/science_fiction/2007/12/index.php$ http://www.majordojo.com/science-fiction/2007/12/index.php [L,R]
RewriteRule ^/television/2007/12/index.php$ http://www.majordojo.com/television/2007/12/index.php [L,R]
RewriteRule ^/aint_it_cool/2007/12/index.php$ http://www.majordojo.com/aint-it-cool/2007/12/index.php [L,R]
RewriteRule ^/aint_it_cool/2007/12/index.php$ http://www.majordojo.com/aint-it-cool/2007/12/index.php [L,R]
RewriteRule ^/its_funny_laugh/2007/12/index.php$ http://www.majordojo.com/its-funny-laugh/2007/12/index.php [L,R]

Additional Resources

Back

2 Comments

budgibson.myopenid.com

budgibson.myopenid.com on May 2, 2008, 9:44 a.m. Reply

One issue with your template is that it does not include the case for subcategories. Also, you have a couple of typos. For instance, a closing div tag somehow wandered into the middle of one of the rules when I copied it. Also, there is an extra MTArchiveList tag in the rules for categories. Here’s my own version of this template that allows for the case of subcategories and seems to work. Same caveats as with yours. People will need to modify.

 RewriteEngine on

<MTIfArchiveTypeEnabled archive_type="Individual">
<MTArchiveList archive_type="Individual">
RewriteRule ^<mt:FileTemplate format="home/archives/%y/%m/%b" />.shtml$ <$mt:BlogURL$><mt:FileTemplate format="archives/%y/%m/%-b" />.shtml [L,R]</MTArchiveList>
</MTIfArchiveTypeEnabled>

<MTIfArchiveTypeEnabled archive_type="Monthly">
<MTArchiveList archive_type="Monthly">
RewriteRule ^<mt:FileTemplate format="archives/%y/%m/" />$ <$mt:BlogURL$><mt:FileTemplate format="archives/%y/%m/" /> [L,R]</MTArchiveList>
</MTIfArchiveTypeEnabled>

<MTIfArchiveTypeEnabled archive_type="Category">
<MTCategories><MTIfNonZero tag="MTCategoryCount">RewriteRule ^<mt:FileTemplate format="home/archives/%c/" />$ <$mt:BlogURL$><mt:FileTemplate format="archives/%-c/" /> [L,R]</MTIfNonZero>
</MTCategories>
</MTIfArchiveTypeEnabled>
Ann Ray

Ann Ray on May 20, 2008, 10:11 a.m. Reply

mod_rewrite is really meant for ongoing aliasing, such as shortening a path or hiding an extension. And step 6 is a wee problem for those of us on shared hosts.

Here’s an alternative when you just want to send people to the new location. And unlike mod_rewrite, this sends a 301 code indicating the move is permanent.

http://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirectpermanent

It can be tedious to create the list, but you can always just map the most recent/popular articles and let the rest go to a custom 404. In my site’s root htaccess, I just added one line per article:

RedirectPermanent /2008/03/watching-for-ov.html http://www.practicalsurveys.com/questionnaires/broadquestions.php

Leave a Comment