When moving a site between blog platforms, developers can sometimes overlook the url changes that occur as a result of moving to the new platform. In my case, I’ve been moving some sites from an older CMS to WordPress. This older CMS was based on ASP.NET, and all urls ended with .aspx file extension. Of course, WordPress urls do not use extensions (or just use the forward slash, I suppose).
So when I imported all the posts to WP, taking care to make sure the post titles titles and permalink settings would make urls the same as the old CMS’ url structure, the urls were still different because of that missing extension.
This detail is easy to miss, but can have a fairly large impact in terms of SEO, lost links, and generally annoyed clients.
Fortunately, setting up redirection from the old url with the file extension, to the new one without an extension is pretty easy to overcome.
The Setup
This is where pretty much all of the work is involved in getting your links to migrate over correctly, and the level of difficulty depends on how your old URLs were generated for what will become your posts.
In our case, the old CMS created URLs in the same way as WordPress: by using the post title as part of the permalink. So, the title:
“Redirect Urls with File Extensions When Migrating to WordPress”
gets converted to:
http://adampaxton/redirect-urls-with-file-extensions-when-migrating-to-wordpress.aspx
So, when exporting the data from the old DB, we made sure the post title was matching up with what we needed to be in the url, because when we import, that is what WP will use for the new permalink by default.
The next step is to verify the permalink settings in Settings > Permalinks. Our implementation was straightforward, and we used the ‘Post name’ option. If you have any hierarchy or category-based url structure, you’ll need to weak the settings here to match.
Importing the actual data can be done with some of the popular CSV import plugins, such as CSV Importer for WordPress.
Getting that Extension off there
Now we have our posts moved over. Let’s pretend you’ve already moved the domain over as well, so our site is effectively live (you’ll be more pragmatic than that), and now the remaining step to get all those old links back working, because that link that was pointed to our old .aspx url will now get a 404.
There are many strategies for handling redirection, some of which require editing the .htaccess file. We don’t have to deal with any of that thanks to Redirections.
The Redirections plugin is built to assist us with exactly what we’re doing – migrating from one blog or CMS platform to WordPress.
Upon installing and activating, go to Tools > Redirection and select ‘Redirects’. You’ll see a screen like the following:
Under Add new redirection, put the following:
- Source URL:
/(.*).aspx
- Regular expression: checked ☑
- Target URL:
/$1/
Note: for source url, replace aspx
with whatever your old system was using, like php
or html
etc.
How It Works
So, what is this doing? We are using a little regular expression in our source url to say “match any url with a forward slash, (some text), a period, and the letters a, s, p, x”.
When we have a match, we then want to redirect to a target url of forward slash, (some text) and another forward slash.
What I’m calling (some text) is actually a capture group, which is defined by parentheses. Our capture group in the Source URL is matching anything. We later reference that capture group in Target URL with $1. If we had another capture group, it would be $2, etc.
What gets passed around in this capture group is the part of the permalink that was based on the post tile, such as “redirect-urls-with-file-extensions-when-migrating-to-wordpress”. And you can see the process of:
“/redirect-urls-with-file-extensions-when-migrating-to-wordpress.aspx”
getting redirected to:
“/redirect-urls-with-file-extensions-when-migrating-to-wordpress/”
which WP will recognize.
Conclusion
So that’s it, using a little pre-import planning, the Redirections plugin, and some regex, we’re saving all those links to the old file extension urls. 👍
You must be logged in to post a comment.