<commit_before>---
layout: post
title: Migrating Blogger to Wordpress Permalinks
categories: []
tags: []
status: publish
type: post
comments: true
meta:
  dsq_thread_id: ''
  _edit_last: '1'
---
I recently migrated my blog from blogger to WordPress. The migration was extremely easy with the automatic importer in WordPress. The only problem is that every single link on the web is pointing to the blogger generated permalinks, which do not match the new WordPress ones.

Since I still get some traffic from other sources, I decided to come up with a method to have the old links redirected to the correct new ones. If you have a list of the old url and the new url, you can use apache's <a href="http://httpd.apache.org/docs/trunk/rewrite/remapping.html">mod_rewrite </a>to automatically redirect the pages without the user ever noticing. The problem here is coming up with that list of equivalent urls without spending hours doing it by hand.

The first problem dealt with getting a list of all the old blogger permalinks. Luckily, I found a '<a href="http://www.bloggerplugins.org/2009/07/table-of-contents-widget-for-blogger.html" target="_blank">plugin</a>' that generates a table of contents with links to every post. Unfortunately, it does it with JavaScript, so you can't just right-click the page and view source to get the links. The way to do it with chrome is as follows:

First right-click over the generated links and select "inspect element".

<img class="size-full wp-image-144 " title="Inspect Element" src="/images/wp/1_inspect_element.png" alt="" width="582" height="317" />

Once the inspect element window appears, right-click on the top HTML tag and select "Copy as HTML". This will let you copy the JavaScript generated HTML. (If you had just clicked view-source, it might not have included that.)

<img class="size-full wp-image-146" title="Copy as HTML" src="/images/wp/2_copy_as_html.png" alt="" width="541" height="252" />

Paste the HTML onto your favorite text editor. I saved it as "toc.html".

[![](/images/wp/3_notepad-527x480.png){: .center-image }](/images/wp/3_notepad.png)

The next step is to get all the 'new' links from the WordPress site. You can export an xml file with all the information in the WordPress settings. I saved that one as "wpexport.xml".

<img class="size-full wp-image-148" title="Wordpress Export" src="/images/wp/4_export_wordpress_xml.png" alt="" width="573" height="573" />

Now that there are two files with the links buried in them, we need to extract them and match them. I wrote a quick <a href="https://github.com/alvarop/alvarop-scripts/blob/master/blogger_to_wordpress_links/blogger_to_wordpress_links.pl">perl script</a> that reads both files, takes the urls, matches as many as it can, and spits out a csv file.

{% highlight bash%}
$ perl blogger_to_wordpress_links.pl > links.csv
{% endhighlight %}

Most of the urls were automatically matched, but a few were not, so I opened up the csv file in excel and filled out the rest. (It puts all of the unmatched urls at the bottom of the file so you only have to cut and paste, not re-type).

<img class=" wp-image-152 " title="CSV List" src="/images/wp/5_csv_link_list.png" alt="" width="608" height="378" />

Ok, so now I have a csv file with URL's, but what I really need is a .htaccess file to actually do the work. I wrote <a href="https://github.com/alvarop/alvarop-scripts/blob/master/blogger_to_wordpress_links/csv_to_htacces.pl">another script</a> to do that.

{% highlight bash%}
$ perl csv_to_htacces.pl links.csv > .htaccess
{% endhighlight %}

The .htaccess file should now redirect any traffic pointed at the 'old' blog and send it to the correct page on the new WordPress one. I did have to manually add a rule for my 'about me' page, but it sure was easier than manually doing 90-something posts! The .htaccess file should end up looking something like this:

{% highlight apache%}
RewriteEngine  on
RewriteRule 2007/05/first-week-of-summer-part-1-of.html http://alvarop.com/2007/05/first-week-of-summer-part-1-of [R]
RewriteRule 2007/05/first-week-of-summer-part-2-of.html http://alvarop.com/2007/06/first-week-of-summer-part-2-of [R]
RewriteRule 2007/05/mid-exam-week-update.html http://alvarop.com/2007/05/mid-exam-week-update [R]
RewriteRule 2007/05/new-phone.html http://alvarop.com/2007/05/new-phone [R]
RewriteRule 2007/05/one-down-four-to-go.html http://alvarop.com/2007/05/one-down-four-to-go [R]
RewriteRule 2007/05/slow-weekend.html http://alvarop.com/2007/05/slow-weekend [R]
RewriteRule 2007/06/5-days-left.html http://alvarop.com/2007/06/5-days-left [R]
RewriteRule 2007/06/boring-friday-and-rest-of-week-update.html http://alvarop.com/2007/06/boring-friday-and-rest-of-week-update [R]
RewriteRule 2007/06/early-morning-update.html http://alvarop.com/2007/06/early-morning-update [R]
{% endhighlight %}

That's it!<commit_msg>Manual image update!<commit_after>---
layout: post
title: Migrating Blogger to Wordpress Permalinks
categories: []
tags: []
status: publish
type: post
comments: true
meta:
  dsq_thread_id: ''
  _edit_last: '1'
---
I recently migrated my blog from blogger to WordPress. The migration was extremely easy with the automatic importer in WordPress. The only problem is that every single link on the web is pointing to the blogger generated permalinks, which do not match the new WordPress ones.

Since I still get some traffic from other sources, I decided to come up with a method to have the old links redirected to the correct new ones. If you have a list of the old url and the new url, you can use apache's <a href="http://httpd.apache.org/docs/trunk/rewrite/remapping.html">mod_rewrite </a>to automatically redirect the pages without the user ever noticing. The problem here is coming up with that list of equivalent urls without spending hours doing it by hand.

The first problem dealt with getting a list of all the old blogger permalinks. Luckily, I found a '<a href="http://www.bloggerplugins.org/2009/07/table-of-contents-widget-for-blogger.html" target="_blank">plugin</a>' that generates a table of contents with links to every post. Unfortunately, it does it with JavaScript, so you can't just right-click the page and view source to get the links. The way to do it with chrome is as follows:

First right-click over the generated links and select "inspect element".

![Inspect Element](/images/wp/1_inspect_element.png){: .center-image }

Once the inspect element window appears, right-click on the top HTML tag and select "Copy as HTML". This will let you copy the JavaScript generated HTML. (If you had just clicked view-source, it might not have included that.)

![Copy as HTML](/images/wp/2_copy_as_html.png){: .center-image }

Paste the HTML onto your favorite text editor. I saved it as "toc.html".

[![](/images/wp/3_notepad-527x480.png){: .center-image }](/images/wp/3_notepad.png)

The next step is to get all the 'new' links from the WordPress site. You can export an xml file with all the information in the WordPress settings. I saved that one as "wpexport.xml".

![Wordpress Export](/images/wp/4_export_wordpress_xml.png){: .center-image }

Now that there are two files with the links buried in them, we need to extract them and match them. I wrote a quick <a href="https://github.com/alvarop/alvarop-scripts/blob/master/blogger_to_wordpress_links/blogger_to_wordpress_links.pl">perl script</a> that reads both files, takes the urls, matches as many as it can, and spits out a csv file.

{% highlight bash%}
$ perl blogger_to_wordpress_links.pl > links.csv
{% endhighlight %}

Most of the urls were automatically matched, but a few were not, so I opened up the csv file in excel and filled out the rest. (It puts all of the unmatched urls at the bottom of the file so you only have to cut and paste, not re-type).

![CSV List](/images/wp/5_csv_link_list.png){: .center-image }

Ok, so now I have a csv file with URL's, but what I really need is a .htaccess file to actually do the work. I wrote <a href="https://github.com/alvarop/alvarop-scripts/blob/master/blogger_to_wordpress_links/csv_to_htacces.pl">another script</a> to do that.

{% highlight bash%}
$ perl csv_to_htacces.pl links.csv > .htaccess
{% endhighlight %}

The .htaccess file should now redirect any traffic pointed at the 'old' blog and send it to the correct page on the new WordPress one. I did have to manually add a rule for my 'about me' page, but it sure was easier than manually doing 90-something posts! The .htaccess file should end up looking something like this:

{% highlight apache%}
RewriteEngine  on
RewriteRule 2007/05/first-week-of-summer-part-1-of.html http://alvarop.com/2007/05/first-week-of-summer-part-1-of [R]
RewriteRule 2007/05/first-week-of-summer-part-2-of.html http://alvarop.com/2007/06/first-week-of-summer-part-2-of [R]
RewriteRule 2007/05/mid-exam-week-update.html http://alvarop.com/2007/05/mid-exam-week-update [R]
RewriteRule 2007/05/new-phone.html http://alvarop.com/2007/05/new-phone [R]
RewriteRule 2007/05/one-down-four-to-go.html http://alvarop.com/2007/05/one-down-four-to-go [R]
RewriteRule 2007/05/slow-weekend.html http://alvarop.com/2007/05/slow-weekend [R]
RewriteRule 2007/06/5-days-left.html http://alvarop.com/2007/06/5-days-left [R]
RewriteRule 2007/06/boring-friday-and-rest-of-week-update.html http://alvarop.com/2007/06/boring-friday-and-rest-of-week-update [R]
RewriteRule 2007/06/early-morning-update.html http://alvarop.com/2007/06/early-morning-update [R]
{% endhighlight %}

That's it!
{'fraction_non_alphanumeric': 0.1055952881783761, 'fraction_numerical': 0.03218342448464451, 'mean_word_length': 4.330156950672646, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5324186', 'n_tokens_mistral': 3272, 'n_tokens_neox': 2909, 'n_words': 1139}