If you use WordPress Pages to manage the content of your site, sometimes you may want a page to actually redirect to another URL – either an external site, or perhaps a subdomain of your existing site. Or maybe you want to redirecting to a static file, such as a PDF.
There are a number of ways this can be done, most of which require adding a plugin to your site. My personal philosophy is that there are a lot of great, feature rich plugins out there, however a lot can be accomplished with just a few lines of simple PHP code. I only use plugins when I feel there is significant benefit.
By creating a simple page template and combining that with a WordPress Custom Field, I can have a flexible and easy to use redirect method.
Step 1: Create the page template, and save the new page in your theme folder as ‘redirect.php’.
<?php
/*
Template Name: Redirect Page
*/
?>
<?php
global $post;
$field = get_post_meta($post->ID, 'redirect', true);
if($field) wp_redirect(clean_url($field), 301);
?>
Step 2: Create a new page
Voila, you have a reusable redirect technique for your WordPress site.