Due to many circumstances, I have a need to upgrade my shared hosting from .Net 3.5 to .Net 4.0. Normally this is no big deal, but I was running my blog on DasBlog, which hasn’t been officially updated since 2009, and it won’t just recompile and run under .Net 4. While there are some branches of their code re-compiled for .Net 4.0, I decided that un-tested code was not for me. I then decided on WordPress for a platform, mostly to continue expanding my horizons outside of Microsoft technology, and also because my hosting provider supports it, and I have more MySQL instances available for database use than SQL Server. I found an excellent post on migrating from DasBlog to WordPress, and used it mostly for a template on what I did, but since I did do some things differently, I decided to document my process. So below are the steps and technologies I utilized to migrate my blog.
Create a Test Environment
For my purposes, the first thing I did was create a Windows 7 virtual machine to do the migration testing. My production site is using shared hosting, so I can’t run a .exe on the server to get the content, which one of the tools I wanted to use required. I installed IIS, PHP, MySQL, and WordPress. I also made a new instance of WordPress in a virtual directory that matched the name of the virtual directory on my production WordPress install.
Set Up DasBlog Locally
I downloaded both the app files and the content from my hosting provider, then placed them in a virtual directory under IIS in my test environment, inside a virtual directory named to match the directory from production. I changed the site name in the DasBlog site.config file to reference the new location so the app would work.
Extract the DasBlog Content
I used DasBlogML to extract the data from DasBlog on the local instance of DasBlog, which outputs a blogML XML file. Some articles imply you need to remove any non-breaking spaces ( ) from the resulting XML, but I didn’t and had no issues.
Import the Data
I added the BlogML Importer plug-in to both my local install of WordPress and my production instance. I used that plug-in from the test instance to import the data and examine the results. For me it worked without issues, bringing over all the posts, comments, and categories. I had about 160 posts to migrate.
Create A WordPress theme
I am still enamored with the current look and feel of my blog which I built for myself as a DasBlog theme. I decided to migrate that HTML layout into a new WordPress theme, instead of using one of the myriad of available themes. I started with the HTLM5 Reset WordPress theme as a base and added the HTML structure and CSS from my DasBlog theme. I ended up modifying quite a few files in the theme in order to get it to work, and getting accustomed to PHP along the way.
Migrate Data and new theme to Production
I zipped up the WordPress theme directory on my test machine, and uploaded it as a theme in my production WordPress instance. Then I migrated the data using the BlogML Importer plug-in. I also had to configure the widgets in the navigation area and manually migrate some data into them.
This is where the real work for the migration begins. Since my blog has existed since 2003, I wanted to maintain my links in search engines as much as possible. I already lost this once when DotNetJunkies (where I began to blog originally) got closed down by Dr. Dobbs, and it killed my comment traffic going forward. The post by Andreas that I was following advocated writing your own Http Module in .Net to handle all the redirects. I initially thought that was the way to go, but I found out that my hosting provider has the URL Rewriting feature installed for IIS7, so I could use the config file route. I figured that would perform better than any code I would write and is likely less buggy, even though over time the code should be used less and less. It also let me handle some of the one-off pages I added on the site that looked like part of DasBlog but really were just static HTML files, as well as some other media content.
There are a number of type of pages that DasBlog uses that need redirect templates:
- Permalink by Guid
DasBlogML also generated a CSV file matching up the DasBlog permalinks with the WordPress permalinks. I used that as a starting point, and also queried the blogML XML file for the guids and dates of each post, and then matched them up with the CSV file in Excel. I then used simple formulas in Excel to generate the XML needed for a static re-write file. Because the number of rewrites is so numerous, I decided to store the mappings in an external file called “maps.config” and reference that from web.config. The basic structure (one example per type) of maps.config is:
And in web.config of the DasBlog virtual directory I added the following section:
To get it to take effect I had to recycle the app pool of the DasBlog app. The important part of the rule is the action. By setting the redirectType to Permanent, it causes IIS to issue a 301 response for the redirect, which tells the caller this is a permanent change. So any search engine should re-write the link in their database and not start you all over again in search engine results. And any other links outside of your site will just redirect automatically.
At this point it seems the new blog is running fine and the redirects are all working. I left the DasBlog instance running, at least for a while. I’m keeping my eye on Google Analytics to see if any other hits show up on the old blog. I am not an expert as DasBlog, so if any other page types show up I’ll find out about it and fix it in the redirect file.