The Science of Web Art, Design and Development

Managing obsolete pages with one line of code

When I switched from Blogger to Wordpress I had to deal with the problem of how to deal with the old pages.

Blogger style of archiving was static. That means that for every post you created, the Blogger system created a static HTML page.

Wordpress on the other side creates pages dynamically, meaning that there is no .html file whatsoever, the page is created on the fly whenever you request it. A change in the database automatically reflects on the page.

Now, the problem is, the address of the new pages doesn’t match the address of the old ones.

While old posts where in URLs like this

http://www.z-oc.com/blog/2006/09/food-links.html

the new posts where called through PHP queries like this

http://www.z-oc.com/blog/2006/09/food-links

But, as long as the post slug is the exact name of the blogger page (without the .html extension) putting the following rule on your .htaccess file should do the trick.

RewriteRule ^(.*)\.html$ http://www.site.com/$1 [R=301,L]

This rule will simple redirect the HTML page to the new address that is exactly the same, but without the .html extension.

Keep in mind though, that this will redirect all pages in your site that end with and .html extension, so take care if you have some .html files around.

You can apply this rule on a per-directory basis or you can put aditiona rules to take care of those in particular.

This way of redirecting is particularly good for SEO, because search engines will be notified that the page was permanently moved, helping them to properly index you site.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • Technorati
  • BlogMemes
  • Ma.gnolia
  • YahooMyWeb
  • Netscape
  • Slashdot
  • StumbleUpon

Related Posts

Trackback URI

9 Comments

  • Great trick! And this is the same trick used by the cache system in the Ruby on Rails framework. The cache system intercept the request, capture the renderized page and record with the same path and the same name a page with .html in the end. And then, the Apache web server returns this new page for the subsequent request, without your database ever noticing it. The performance gain astonish me.

    Tuesday, 8 May 2007, 4:59
  • Nice, Fabio, I didn’t know that.

    Can you share numbers about the performace gain?

    Tuesday, 8 May 2007, 5:12
  • The answer is: it depends. Any other answer would be a great mistake. It depend how complex is your page, if it do queries on your database and how powerful is your server. For me, in my specific case and in my specific machine, the gain is something between 10x and 40x. My recommendation: for any real application, you MUST turn on the cache system. The Ruby is a interpreted language, and because of this it suffer from performance problems.

    Tuesday, 8 May 2007, 5:23
  • Nice overview, thanks for sharing the data.

    Tuesday, 8 May 2007, 5:55
  • Ryan Imel says:

    Great tip! I could see this being very useful for anyone transitioning from Blogger to Wordpress. I like.

    Thanks.

    Friday, 6 July 2007, 5:24
  • Thanks Ryan, and thanks for featuring this post on your blog.

    Friday, 6 July 2007, 7:08
  • actually just putting the rewrite for the HTML won’t work. because while importing from blogger to wordpress, wordpress changes the the post slugs for certain post hence your permalinks also change. I have listed a workaround on my blog post, you’ll need to modify the blogger.php importer source code and add a extra line to import the post slugs correctly.

    Sunday, 22 July 2007, 22:34
  • @Arpit Jacob - You are right, I do mentioned that the post slugs have to be the same. Nice to have your solution to make it happen.

    Sunday, 22 July 2007, 22:45

Trackbacks

  1. Reviews of Wordpress Plugins and Themes | Testing Free WordPress Themes | Wordpress Tutorials and Tips » We really like WordPress. We like it so much we have dedicated this entire site to WordPress themes, WordPress advice and tutorials, and (if you fanc
  2. WordPress Wednesday News: WordPress 2.3 News, WordPress 2.2.3 Released, WordPressMU Upgraded, WordCamp Israel, Breaking WordPress Plugins, and Counting Words : The Blog Herald

Share your thoughts

(Comments are dofollow, but also moderated. Don't forget to check the box stating that you are human before you submit your comment.)