Simple page or section redirect in WordPress
Recently we had a chance to re-code the old client site: Graniti-Sušec. The site was first developed back in 2003. and was in fact the first commercial (non-personal) site done with web standards in Croatia.
At that time I was much more involved with ASP 2.0 and only heard about PHP. But since then — my focus shifted far, far away from ASP, and we decided not to fix the ancient codebase, but to move the backend to WordPress.
With the migration, we had to take care about the new URL scheme. The language part of previous scheme was full-length language name and therefor clumsy. The transition had to be seamless, so we don’t cut-off visitors landing from Google.
The solution is quite simple. All pages are organized as a child pages of two parents: /hr/ and /en/. We created two additional first-level pages — /hrvatska/ and /english/ — and set both pages’ templates to “Page Redirect”. This is how it’s done step by step:
Step 1: Create page template
In your WordPress theme folder create new blank file: page-redirect.php, paste the code below and save it. Keep in mind that there’s no space left before <?php or after ?> or it might throw you an error.
<?php
/*
Template Name: Page Redirect
*/
header('HTTP/1.1 301 Moved Permanently');
$redirect_url = get_post_meta($post->ID, 'redirect_url', true);
if (!empty($redirect_url)) {
header('Location: ' . $redirect_url);
} else {
header('Location: /');
}
?>
Step 2: Add New Page
Create new page in WordPress (Pages » Add New), and paste the old URL into Permalink field — right below the title field.
Step 3: Add custom field
In Custom Fields box, enter new custom field, named redirect_url and set the value to new URL.
Step 4: Choose page template
In attribute box (usually on the right hand side), there is Templates drop-down. Select “Page Redirect” and hit Publish.
Type the old URL into browser’s address bar, and it should be instantly redirected to your new URL. WordPress will also automagically redirect all child pages, so in my example /english/marble/ redirects to /en/marble/.

001—2010.02.24.20:25
Cool tip! Very clever…
Looks like you are becoming a WP guru ;)