How to migrate URL’s from a newspaper website to WordPress

This is one of the biggest issues when migrating a newspaper from one system to the other, because it’s all about ensuring your old traffic isn’t lost while creating a new website. For example, if your old website formatted the URL’s (the address which appears in your browsers address bar) appeared as http://[yourdomain]/articles/1010.html you’ll want to ensure that you redirect users away from the /articles/1010.html portion and they instead land on the new version, which will likely (assuming you’re using permalinks) appear as something similar to /your-story-title/ on the new site.

To do this, there are a couple methods that I follow.

Coding a Custom Solution

First, when migrating the website I move the old address of the article into a hidden meta field in the new article. This allows me to access the old URL (/articles/1010.html) through PHP without cluttering the interface for website editors. To create a hidden meta field in WordPress, simply add the _ symbol to your meta field name.

To make this work, simple ensure that you migrate the old URL (/articles/1010.html) into this field so that WordPress knows what the old address was but remember to only include the path, not the full URL.

Next, make use of the template_redirect hook in WordPress to redirect a page based on the hidden value. This works almost the same as my earlier post on redirecting a single post in WordPress but instead, we’ll tie into it based on the current 404 error.

?

/**
* redirects browser if hidden meta field matches
*
*/
function thisismyurl_redirect_old_url() {

if ( is_404() ) {

$current_url = $_SERVER[“REQUEST_URI”];

if ( !empty( $current_url ) ) {

$args = array(
‘meta_key’ => ‘_old_url’,
‘meta_value’ => $current_url
);

$new_post_url = get_posts( $args );

if ( !empty( $new_post_url ) )
$redirect = get_permalink( $new_post_url[0]->ID );

if ( !empty( $redirect ) ) {
wp_redirect( $redirect, 301 );
die();
}
}
}

}
add_action( ‘template_redirect’,’thisismyurl_redirect_old_url’ );
With this little snippet of code, WordPress will not only redirect visitors trying to access the old URL (/articles/1010.html) to the new URL (/your-story-title/) but using the 301 error code it will also tell search engines that the page has moved permanently to the new location, protecting your existing SEO while migrating to WordPress.

Using Plugins

The second method that I’ve used in the past is Daniel Bachhuber’s fantastic CP Redirect plugin. While it’s not specifically designed for this task, it’s very close and can be made to work perfectly. If you recognize the name, Daniel’s one of the masterminds behind EditFlow, one of my favourite WordPress plugins.

Leave a Reply

Your email address will not be published. Required fields are marked *