March 16, 2003

restructuring default archives

If you are new to blogging then "starting a blog - with movabletype":http://nslog.com/archives/2003/03/13/starting_a_blog_with_movabletype.php may be a worthwhile read. I looks like he "ran into the same problem I did":http://nslog.com/archives/2003/02/22/grrrr_site_organization.php. As a side note I decided to do this on "andersja's adivce":http://www.jacobsen.no/anders/blog/archives/2002/08/06/my_movable_type_installation.html. I did decide that the depth (to the day) was overkill for my site and decided to just use /archives/year/month/title.php as my archive location. After scanning through my access_log I noticed that there are still a sizable number of requests for some of the pages that were in the default location (i.e. /archives/000057.html). So I decided to see if I could fix this problem! My solution is to let movabletype create an .htaccess (I am hosted on apache - I don't know how to do this for IIS) file in the /archives/ directory that uses "mod_rewrite":http://www.engelschall.com/pw/apache/rewriteguide/ to redirect folks to the new permalink (note: after building it once you can disable rebuilding automatically because new entries will not have been at the old location). To do this I created a new index template with the output specified as archives/.htaccess (you should make sure you don't already have a hand created .htaccess file in this location first). Here is the "source of the index template":/log/projects/movabletype/dot_htaccess_archive_template.txt : == RewriteEngine On
<MTEntries sort_order="ascend" last_n="300000">
RewriteCond %{REQUEST_URI} <$MTEntryID pad="6"$>.html$
RewriteRule .* <$MTEntryLink$> [R,L]
</MTEntries>
== The "final .htaccess file":/log/projects/movabletype/dot_htaccess.txt looks like this : == RewriteEngine On
RewriteCond %{REQUEST_URI} 000001.html$
RewriteRule .* http://www.khakipants.org/archives/2002/08/new_site.html [R,L]
RewriteCond %{REQUEST_URI} 000002.html$
RewriteRule .* http://www.khakipants.org/archives/2002/08/old_content.html [R,L]
RewriteCond %{REQUEST_URI} 000003.html$
RewriteRule .* http://www.khakipants.org/archives/2002/08/john_earles_last_day.html [R,L]
RewriteCond %{REQUEST_URI} 000004.html$
RewriteRule .* http://www.khakipants.org/archives/2002/08/preparing_for_class.html [R,L]
...
== Each RewriteCond line matches a given old permalink location and each RewriteRule line redirects incoming requests to the current permalink location. Give it a try to "see how it works":/archives/000057.html. Similar rules could be added to handle category archives etc. This is just the sort of refactoring task that could potentially be handled automagically by blogging software. updated: /archives/.htaccess has been merged with /.htaccess so that canonicalization rules will work properly. Also, I have the redirect rules returing the appropriate HTTP code. And the sample files have been updated.
comments (3) | [popular, site admin]

Related Entries

TrackBacks

Site Reorganization from TooMuchSexy.blog
Site Reorganization from Primate Control
Friday Feast #55: Friendly, Lasting URLs from Brainstorms and Raves
Concessions from ne(one)piphany
the site from birthday boat cardboard chat computer directtv dolphin ecard employment envelope font friends internet massage nurse paper party personals poetry rose school scooter shareware smoking stamp sword tigers tires work

Comments

  1. posted by: Andrew on May 29, 2003 11:00 PM

    Thank you very, very much for this tip....without it I wouldn't have been able to redo my weblogs into a cleaner URL structure.

  2. posted by: Raquel on March 30, 2004 12:05 PM

    Found this link while searching Google, thanks

  3. posted by: mariano on May 6, 2004 6:49 PM

    many thanks nathan.. after a few tweaks.. i could get mi blog online.. again :)

Post a comment

Name:


Email Address:


URL:


Comments: