Migrate from BlogEngine.NET to WordPress

I just had the opportunity to migrate or company blog from BlogEngine.NET to WordPress. It was not fun, or easy so thought I would share it with you.

There are a few things to note with this process.  Following these steps will import Posts, Authors, Categories, and Comments.  It will not migrate tags.  The conversion script I wrote will give you a list of tags that were associated with each post for you to manually fix later.

 

Step 1 – Export the data:

We need to export your current blog information.  To do this, log in to your existing BlogEngine.NET Blog.  Open Settings and at the bottom under Import & Export Click Export.

1

Save the BlogML.xml file to a location you will remember.

 

Step 2 – Convert the data:

Run my conversion script to make the BlogML file compatible with WordPress.

Download the BlogEngineToWordpress import script from My Downloads Page.  This script needs a few lines at the top changed before use.

Open the script and in the Config section, set the following to match your environment:

BlogEngineExportFile: The path to the BlogML.xml file that we downloaded earlier.

outputFolder: The path where you want the new files to go.

blogDomain: The URL that points to your blog.

imageURLPrefix: This path will be appended to blogDomain and will point to all the image files that will be imported to wordpress.

postURLPrefix: This path will be appended to blogDomain and will point to all the posts that will be imported to wordpress.

spacesInTab: The number of spaces in a tab.  I use this when I create the redirect rules that I will add to the web.config file in IIS.

Save the changes you have made and run the script at a command prompts as cscript BlogEngineToWordpress.vbs.

Note: This is not a perfect script.  There are still some things that may go wrong.  If there are weird symbols or incorrect html in the existing posts, the script will fail. 

If this happens, open the WPImport.xml file, scroll to the bottom, and see what post failed.  Then open the BlogML.xml file, find the bad post and fix the issues.  (Usually removing weird symbols that notepad cannot understand).  Save the files and try again.

If you need help trying to find out what is wrong, you can set the variable enableDebuging to true in the Config section.  This may help if you want to dig into the code a little bit.

If you still cannot get past a problem post, I recommend deleting the data between the <![CDATA[    ]]> tags in the BlogML.xml file.  This way you will still migrate the post to the new system, it will just be blank.  You can then edit that post in the WordPress UI add re add the text.

After a few bad posts that I had to fix, 8 out of about 900 for me.  I finally saw the end of the script.

The script created 6 files.  They are:

postsAndTags.txt – A list of the old URL to each post and the tags that were associated with it.

redirectFile.txt – A comma separated list of the old and new urls.

redirectNeedsFixedFile.txt – A comma separated list or URLs that I was unable to fix.  (You will manually have to update these)

web.config_partial – The list of rewrites you will need to add to the web.config file in IIS if you want to use rewriteMaps.

web2.config_partial – The list of rewrites you will need to add to the web.config file in IIS if you want to use redirectRules.

WPImport.xml – A WordPress compatible import file.

If redirectNeedsFixedFile.txt is empty then you are done with the conversion step and are ready to skip to Step 3 and importing the data.

If your redirectNeedsFixedFile.txt is not empty we will need to address this.  I have 11 urls in this list, most of them pointing to “Pages” on the old blog.  I don’t use pages so most of these can go.

1- /Blog/admin/Pages/www.groupon.com,/needtofix/page//blog/admin/pages/www.groupon.com

This is line 1 for me.  the left hand /Blog/admin/Pages/www.groupon.com looks like a malformed url.  I want o be certain though so I opened it in a browser.  I got a 404 Page Does Not Exist error.  Now I need to fix the import data.

Open WPImport.xml and search for the string on the right

/needtofix/page//blog/admin/pages/www.groupon.com

I found only one occurrence and it looked like a link to http://www.groupon.com”> so I updated it.

2 – /blog/,

Line 2 is a special one.  I think every site will have one of these.  This is saying that the old site had a link to /blog/, but every link on my blog will have this because it lives in a subfolder on my site.  I can ignore this one.

3 – /Blog/?tag=/saving+money,/needtofix/tag//blog/?tag=/saving+money

Line 3 is a link to a list of tags.  When I wrote this script, I did not add the ability to update URLs that point to tags or pages. I didn’t need to feature and I was in a time crunch.  If you have many URLs in this list because of links to tags or pages, leave a comment and I will try to update the script soon.

If you don’t have many links like this you can manually update them.  Search for the string to the right of the comma in the WPImport.xml file and update it accordingly.

4 – http://www.rollinzrox.com/blog/,/needtofix/other/http://www.rollinzrox.com/blog/

Line 4 is a link to another blog.  The way I fix URLs caught this one and placed it in my other broken URL list.  I have to manually set this back to the way it was.  In WPImport.xml replace the text to the right of the comma with the text on the left of the comma.

 

Step 3 – Import the data:

When we are finally done converting the data, we need to import it into WordPress.  Here is what we need to do:

Download the BlogML importer plugin for WordPress from http://wordpress.org/extend/plugins/blogml-importer/

This is a plugin written by Aaron Lerch.  You can read about his experiences changing blogging platforms at aaronlerch.com

Log into your new WordPress Blog.

Open Plugins and then Add New.  Click on the Upload link at the lop and point it to the zip file you just downloaded.

Click the Install now button.

Click Activate Plugin.

Go to the Tools –> Import screen and Click on BlogML

If your WPImport.xml file is large than 2 mb we will need to increase the upload size in our php.ini file.  I am doing this on a self hosted machine that I control so the process might be a little bit different for you.

Open your php.ini file and change the following two lines:

upload_max_filesize = 10M

post_max_size = 10M

Now restart IIS and upload the WPImport.xml file

It will take a little while to upload depending on your internet speed.

After the file completes the upload, the plugin asks about importing users.  You have the ability to import all the old users or to map them old users to new ones.  Make you choices and click Submit.

The data is now importing into WordPress.  This will take a while if you have many posts.

After a healthy amount of time, you will see a page with a (possibly) long list of post titles.  When you see this, you can be happy because you know that the data import to WordPress is now done.

Return to your dashboard and see the results of the data import.

 

Step 4 – Move the media:

Now you have all the posts and authors and comments moved over, but now pictures.  We will need to manually copy the pictures and other media to the new blog.

You will need to copy all the files out of the BlogEngine media folder (for me this was at C:InetpubBlogEngine.NETApp_Datafiles) into the WordPress uploads folder.

The location in the uploads folder depends on the path you set in the conversion script.  The variable imageURLPrefix set the path.  I wanted the content to be located in wp-content/uploads/1000/01.

Copy the files and check the posts on the blog.  Verify that WordPress can find the files.

 

Step 5 – Add new media to Media Library (Optional):

This step is optional.  After you copy the images to the WordPress uploads folder, all the posts will be able to see them correctly, but they will not be accessible via the WordPress UI.  If this bothers you, there is a plugin available that will allow you to import the files and you them with the WordPress media manager.

(This plugin will also bulk up the folder that contains the images.  The plugin creates 3 additional copies of each file, each with a different size.)

Download the plugin from http://wordpress.org/extend/plugins/add-from-server/ and add it the same way we added the BlogML import plugin.

Activate the plugin.

On the page with the Plugin list, click ………

Browse to the files that you want to add (this took a while to list them all for me.  A popup from IE kept asking me if I wanted to stop a script that was slowing down the webpage.  I repeatedly clicked No, Don’t stop the script.)

Check the boxes next to all the files and click Import.

 

Step 6 – Redirect rules:

Now we have one of the most important parts of the migration.  We need to add all the redirect rules to IIS so we don’t look bad to search engines.

Decide if you want to use an individual redirect rule for each URL or if you want to use a rewrite map.  I chose to use a rewrite map because it is smaller.

Open up you web.config file for your WordPress site and add the text from the web.config_partial (or web2.config_partial) file that was created by the conversion script.

Insert the text after the first <rewrite> tag, but before the first <rule> tag.

If you choose the redirectMap, you will also need to add this rule before the default WordPress rule:

<rule name=”WP Redirect Rule” enabled=”true”>
<match url=”.*”/>
<conditions>
<add input=”{StaticRedirects:{REQUEST_URI}}” pattern=”(.+)”/>
</conditions>
<action type=”Redirect” url=http://www.myblog.com{c:1} redirectType=”Permanent” appendQueryString=”false”/>
</rule>

Save your web.config file.  If your web.config file is larger than 250kb we need to edit the registry to increase the allowed size.

Open regedit and add the following DWORD value to HKLMSOFTWAREMicrosoftInetStpConfiguration and

HKLMSOFTWAREWow6432NodeMicrosoftInetStpConfiguration

DWORD “MaxWebConfigFileSizeInKB” = Decimal “1000”

(You may have to create the Configuration Key as well.)

After editing the registry,  you will need to reboot the server.

After the reboot, (or after editing web.config and not needing to reboot)

Browse to one of the old URLs to verify the redirect.

 

Step 7 – Add tags and fix any other issues:

Unfortunately the conversion scripts do not add the tags to all the posts for you.  We have to manually do that now.  Open up the pastsAndTags.txt file and browse to the main page of your blog.  Manually edit each post and edit the tags.  This may take a while, but I think it is worth it to verify that everything is working.

During this time you can also check that all the images work.  Some images I had were broken because BlogEngine.Net passes in files with spaces in the name with a + icon.  I had to edit the links to any pictures with a + in the name to point to the right place.

 

Done:

Well, that is all I can think of right now.  I will update the post if I can think of anything else.

This entry was posted in Uncategorized. Bookmark the permalink.