Dynamic Sitemap

About two years ago I wrote a program that created a sitemap from a local copy of my web pages (I also wrote an automation wrapper so that I could do all my web sites along with other mundane tasks reliably).

When I installed WordPress over a year ago I really liked the fact that the sitemap plug in was capable of dynamically creating a sitemap when a request was made; and I set it as a goal to implement that on my web site.

Well, yesterday that goal was realized.

I wrote a simple PHP script that takes some meta information and creates a sitemap, either uncompressed or compressed based on what is requested.  I used a rewrite rule in my .htaccess file to allow search engines to continue to request the familiar sitemap.xml and/or sitemap.xml.gz file.

Now I don’t have to worry about creating and deploying a sitemap file when I change a file; I only have to make sure that the meta information is updated when I add or remove pages.  Plus, I incorporated the concept of dynamic pages, so that the sitemap can accurately report fresh content.

At the moment I haven’t decided if I’m going to “publish” this code or not.  It’s likely I will once I clean it up and actually test it more completely.  Like I said, it isn’t rocket science – it just takes a little knowledge of what a sitemap is, and you can get everything you need from sitemaps.org; a little ability in PHP, and a basic understanding of how to write a re-write rule for Apache.

Originally posted 2010-02-23 01:00:50.