Redirecting visitors and search engines from one page to another is crucial for WordPress websites. To be frank, this practice is pivotal for just about any resource on the World Wide Web. It points visitors and search engines alike to the intended URL (Uniform Resource Locator). As you can probably guess, non-functional URL results in a page hanging and eventually failing to open, showing a “404 – Page Not Found” error. Since dead links are detrimental to your website, both from the perspective of search engine crawlers and human visitors, you need a prompt solution. That’s where learning how to redirect a page in WordPress comes in. Let’s begin.
Note. We will assume you want to perform a 301 redirect, i.e., permanently redirect one page to another. Even if that isn’t the case, we suggest you test things on a staging website nonetheless.
1. Redirecting a page in WordPress in the .htaccess file
We nearly always begin with methods that require few resources, time, and effort. That applies here, though editing your source WordPress files is often daunting for beginners. Don’t fret—it’s just one page, and you can easily revert changes. Follow these instructions to redirect a WordPress page within the .htaccess file:
- Access WordPress website using FTP.
- Head to the root folder (oftentimes titled www or public_html), and right-click the .htaccess file.
- Select View/Edit, Download, or Code Editor, depending on what’s available.
- Scroll to the bottom of the file and enter this simple code:
RewriteEngine On
Redirect 301 /old-page https://www.your-website.com/new-page - Replace “old-page” and “new-page”. Make sure to add/remove “www” or change “https” into “http” if you haven’t employed an SSL certificate, though you should.
- Click on Save, Save Changes, or Save & Close.
Several pages to one page (Optional)
You can also set up multiple pages to direct to a single page, which uses the wildcard redirect we explained below. For example, if pages from one category need to redirect to a single page, it would look like this:
RedirectMatch /category/page(.*)$ https://www.your-website.com/new-page
Any page in a given category that contains the specified element (“page”) will now redirect to the new page you set up.
2. Redirect a page using a WordPress plugin
User-friendliness, convenience, and safety are primary concerns when redirecting pages. Unless you perform this properly, you may alienate visitors and crawlers alike and lose audience and ranking. We’ll demonstrate the procedure with one well-known free WordPress plugin, but there are plenty like it. Luckily, the basics hold regardless of your choice.
Installing the plugin and setting up things
Install Redirection from the WordPress repository. We have already shown how WordPress plugin installation works.
Activate it afterward, and then begin the procedure by heading over to the Tools section in the left sidebar of your WordPress Admin. Select Redirection from the list. You’ll be met with a “Welcome to a Redirection” page. Click on the Start Setup button.
Automatic redirection
You’ll now see a “Basic Setup” page with 3 options. However, the first two are the reason we chose Redirection over simpler plugins for demonstration.
- Monitor permalink changes in WordPress posts and pages
- Keep a log of all redirects and 404 errors
As you can see, the plugin has an auto-detection tool that will scan all pages on your website. It will determine which URLs are dead, create a detailed log, and set up a redirect automatically. This will save you a lot of time, especially when rebranding or changing your permalink structure. Tick the two boxes if you need this sort of thing, then click on Continue Setup. After Redirection tests the REST API (Application Programming Interface) required for the plugin’s functionality and states “Good”, click on Finish Setup.
Manual redirect
You’ll now see the plugin’s dashboard. It may already contain some entries it detected if you opted for the previous option. Now, to set up a manual redirection for a single page in WordPress via Redirection, do the following:
- Find the Add new redirection section.
- Type your old page URL in the Source URL field. There’s no need to enter the domain name, only the part after /.
- Leave Query Parameters alone in this case.
- The new page URL goes into the Target URL field.
- Leave Redirections (the default option) under “Group” for a permanent redirect.
Change the option for other types of redirects. For instance, pick Modified posts if the old URL is an outdated page and the new page URL is its updated version. - Optional. Click the gearbox icon next to “Add Redirect” to see extra options. We selected Redirect to URL under “When matched” and 301 – Moved Permanently under “with HTTP code”.
- All that’s left is to click the Add Redirect button. The newly added redirect will appear on the dashboard page.
Wildcard redirects
Decided to tweak permalink structure or redirect certain pages under a new category, say, Definitions? That means you’ll need to redirect your visitors from, for instance, “~/what-is/page-name” to “~/definitions/page-name”. If you have a few pages, it may make sense to use the method above. Otherwise, it makes manual redirection configuration a waste of time and effort. Wildcard redirect comes can recognize all pages that share an element and apply redirection across the board in one click.
To start, go back to the Add new redirection section. Now, follow these steps to configure manual wildcard page redirect through Redirection in WordPress:
- Enter “/outdated-category/(.*)$” without quotation marks under Source URL. For example, we would enter /what-is/(.*)$
- Select REGEX from the list of options in the top right corner.
- Type “/new-category/$1” without quotation marks for Target URL. Replace it with yours. We typed /definitions/$1.
- Click on Add Redirect.
3. Perform page redirect within functions.php in WordPress
There is no sense editing the functions.php file inside the folder of your WordPress theme (wp-content/themes/theme-name/), or, ideally, a child theme, to redirect a single page. Instead, we only suggest this to advanced users who know some code and want to build upon this for their purposes. This function also automatically prefers HTTPS pages over HTTP ones. Here’s how that code snippet looks:
function redirect_page() {
if (isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$protocol = 'https://';
}
else {
$protocol = 'http://';
}
$currenturl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$currenturl_relative = wp_make_link_relative($currenturl);
echo $currenturl_relative;
switch ($currenturl_relative) {
case '/old-page':
$urlto = home_url('/new-page');
break;
default:
return;
}
if ($currenturl != $urlto)
exit( wp_redirect( $urlto ) );
}
add_action( 'template_redirect', 'redirect_page' );
You only need to change old-page and new-page with actual WordPress page names.