So yesterday was a bit of a scavenger hunt through the bowels of incredibly old articles on the Internet, resulting in a few dead-ends, some u-turns, false starts and finally pretty successfully accomplishing my goal.
You see, a friend asked how she could redirect her old Movable Type blog to her new WordPress blog so that when people look for her via Google, they will find her most current version. It seems pretty straight forward at first, and if we were just thinking about the high level domain/url for her MT blog, to her WP blog, you’d think a simple 301 redirect would do the trick. But what about all of the individual pages? The Category Archives? The Monthly Archives? Not to mention all of the tags? Redirecting Movable Type Blogs to WordPress is not as straightforward as it seems. If you don’t care about the journey, skip down to the bottom, Redirecting Movable Type Blogs to WordPress Step by Step.
Redirecting Individual Entry Archives
Let me state right off the bat that a lot was written about this … 7 – 11 years ago! That’s right because you see, the version of Movable Type in this case is from 2006 and when WordPress first came on the scene, lots of people were migrating from Movable Type to WordPress, so there was a need for some easy to understand instructions. Unfortunately, though what this meant to me was that a lot of these articles were, well, gone. Let me also state that this assumes you’ve already imported your entries from Movable Type to WordPress and you’ve used entry URLs are formatted in Movable Type as www.yourwebsite.com/yyyy/mm/post_name.ext (where .ext is html, htm, php, etc. – more on this later) and your WordPress URLs (permalinks) are www.yournewwebsite.com/yyyy/mm/post-name/. If you need help with the import, check out: Importing Movable Type 3.x Blogs into WordPress.
To start, I had this article in the WordPress archives: Importing from Movable Type to WordPress. It’s got the basic steps you need to move your blog (import/export) from Movable Type to WordPress but not much on the redirection. It did have a valuable clue, referencing Alex King’s Movable Type Template for Individual Entries, “which you can use to generate pages that will redirect visitors to the corresponding WordPress pages.” That’s exactly what I needed!
Unfortunately, the link was broken. It did get me to AlexKing.Org (side note, Alex King was one of the original developers of WordPress). Doing a search though on his blog using the term “Redirecting MT Entries”, led me to this post, “Redirecting MT Entries to WP” which led to his WordPress Hacks and to Jonathan Green’s Moving from Movable Type to WordPress.
On the Hacks page (you need to page down), you’ll find, “Redirect MoveableType to WordPress Template” which you can download. It’s a zip file that contains a PHP template for 301 redirection, an html template for redirection and a readme file. Looking back, here’s about the time I took my first misstep (but I’ll explain why later).
A Sidebar – on SEO (Search Engine Optimization)
Back on the Redirection Course
Anyway, once I made the decision to use the PHP template, I went over to the MT installation, backed up the existing Individual Entry Archive, and then copied over it with the PHP template, changing the URL in the template. I rebuilt the blog but the new entries did not redirect. I looked at the code and realized (and honestly it clearly states), that the template assumes the URLs are of the format, www.yourwebsite.com/yyyy/mm/dd/post_name.ext. So I took out the code for the days (dd) and rebuilt the blog. It still didn’t work. I added this line to the code,
"$title = str_replace('_', '-', $title);" because it seemed to me there was nothing in the function that converts the underscores in the title to dashes (of course, I could be wrong). It still didn’t work.
So I returned to Jonathan Green’s article since he stated that he got this template to work. That’s when I notices he stated:
I should note here that you will have to change the way MT generates pages BEFORE using the new template.
So I reread that paragraph again. Yep, you see all the pages on this blog had an .html extension. They needed to be php. But before I accepted that, I re-read Alex’s Read Me file, where he stated,
If you have .html archives but want to use the .php redirects, you can put this in a .htaccess file in your MT directory:
AddType application/x-httpd-php .html
Then all your .html pages will be parsed by PHP
That seemed easier and more straight forward and since I had FTP access to the blog, I created an .htaccess file and uploaded it to the server.
It still didn’t work.
Returning to Jonathan’s advice, I returned the Individual Entry Archive to its original form, rebuilt the blog (so all the html pages returned), went into Settings–>Publishing on the MT Installation, changed the File Extension for Archive Files from html to php (no period), clicked Save, then returned to the Templates.
Then, in the Templates–> Archives, I opened the Individual Entry Archive, copied back in the template file for PHP (with the changes to only do YYYY-MM files directories), saved it and rebuilt the blog.
The blog rebuilt with the individual pages having the php extension and those pages automatically redirected to the new blog location!
Wait though. What about all those html pages for the blog? Weren’t they still out there? Oh, and didn’t Google still point to those pages not the php pages that were now redirecting? So yes, while from the MT Blog home page, the links redirected to the new WP blog, it didn’t help with the search at all.
Rereading Jonathan’s article yet again and saw this:
I am still working on a .htaccess redirect for my .html files to redirect to the .php ones so that they can take advantage of the new template as well. This will automatically push someone from Google to the right spot in my WordPress site. Right now I am getting a 500 Error and will need to try again in the am… – See more at: http://www.atmasphere.net/archives/2004/03/29/moving-from-moveabletype-to-wordpress#sthash.srveSLI2.dpuf
Great. I already tried using an .htaccess file and it didn’t work. That’s when something jogged in my memory. You see, .htaccess files are used on servers that operate under Apache and well, I had the sinking feeling that the server on which the MT blog resided was a windows-based server. There was no using an .htaccess file.
So now I was sent researching how to do redirects (now I needed to redirect the MT .html files to the MT .php files which in turn would then redirect to the new WP blog) on a Windows platform. The results weren’t encouraging. The prevailing opinion through the myriad of articles I read seemed to state that they only way to do this was through the admin panel, one file at a time, I had neither the access or desire to do that.
Then I found some articles that indicated I could accomplish this through the web.config file. Long story short though, I could not get this to work either.
Then through some more digging I stumbled upon a Japanese blog (I used Google Translate), which had a Movable Type Plugin that appeared would send the Permalink to a corresponding alias. It worked beautifully! Unfortunately though only if the original URL and the Alias URL were explicitly spelled out and it only had places for five aliases. So no using wildcards and no more than five pages could be redirected.
<MTSetVarBlock name=”PHPFileName”>http://oldblogwebsite.com/<$MTArchiveDate format=”%Y/%m/”$><$MTEntryTitle dirify=”1″ trim_to=”30″$>.php</MTSetVarBlock>
This creates the PHP file name in the variable PHPFileName. Note though the “trim_to” field. This truncates the Entry Title in the same way Movable Type does when creating the Permalink. Make sure yours it’s not longer than your longest file name.
Finally I had the correct url! I put that bit of code in the Head section of the Individual Archive Template (the original one that builds the html pages), right before the end. Then in the body section, at the beginning, I placed:
I’m not sure I had to do it this way. I may have been able to $MTGetVar command right into the location.replace but when I did try that initially, it didn’t work (later I realized I had a typo so I’m not sure if that was the cause for it not working). In the end though, this worked so I kept it!
The Original Error to Which I Alluded
So now I have html versions that redirected to the php versions that redirected using a 301 to the new blog for each individual entry. I’m not sure how this will affect the SEO as the 301 is on the php version not the html but at this point I can’t afford more time on this issue. It’s this morning though, when I went through these steps in my head that I realized if I was giving up on the 301 redirect, I could have just put this bit of code in the html files via the Individual Entry Archive and had them point directly to the new blog. Oh well.
Now, about the other pages in the blog…
Redirecting Movable Type Blogs to WordPress Step by Step
Using PHP 301 Redirect in the Individual Entry Archive
1. In your html version (if you are starting with html) of your Individual Entry Archive add this code:
<MTSetVarBlock name=”PHPFileName”>http://oldblogwebsite.com/<$MTArchiveDate format=”%Y/%m/”$><$MTEntryTitle dirify=”1″ trim_to=”30″$>.php</MTSetVarBlock> in the Head section, just before the end. Ensure that your Individual Entries follow the naming convention, “http://oldblogwebsite.com/yyyy/mm/entry_name.html” and make sure your trim is to the correct number.
2. Also in the html version of your Individual Entry Archive, just after the “Body” starts, add this code:
3. Rebuild all of your Individual Archives.
4. Now using the PHP by Alex King, referenced above, copy that into your Individual Entry Archive file (paying attention again to the use of days in your archive URL).
5. In Settings–>Publishing, change the file extension (as shown above) to PHP. Rebuild your individual archives again. Now all of the individual pages will redirect to your new blog.
1. If you don’t care about the 301 redirect, this is much easier. In your html version of your Individual Entry Archive add this code:
<MTSetVarBlock name=”PHPFileName”>http://oldblogwebsite.com/<$MTArchiveDate format=”%Y/%m/”$><$MTEntryTitle dirify=”-” trim_to=”30″$>.php</MTSetVarBlock> in the Head section, just before the end. Ensure that your Individual Entries follow the naming convention, “http://oldblogwebsite.com/yyyy/mm/entry_name.html” and make sure your trim is to the correct number. Note: the dirify is changed from a “1” to a “-” this will return the entry titles with a dash where the spaces are in the Entry Title, making it suitable for a WordPress URL.
3. Rebuild the Individual Archives and you’re done.
It’s all very similar to the Individual Entry Archives, again, not worrying about the 301 redirect, add this code to your Category Archive page near the end of the head section:
<MTSetVarBlock name=”NewFileName”>http://cindysbakedalaska.com/category/<$MTArchiveTitle dirify=”-“$>/</MTSetVarBlock>
Again, all very similar. Add the code below to the Head section just before the end:
<MTSetVarBlock name=”NewFileName”>http://cindysbakedalaska.com/<$MTArchiveDate format=”%Y/%m/”$>/</MTSetVarBlock>
Unfortunately I haven’t figured out how to redirect these yet.
Then save and rebuild. That’s it, your site will totally be forwarded to the new domain.