If you’ve redesigned your site or made revisions to your permalink structure, chances are that many of your URLs have changed. This is an issue for search engines and users alike. Fortunately, WordPress redirects offer a simple solution. By using a redirect, your visitors won’t be negatively impacted, and you’ll be able to keep your search engine rankings intact.
On this page, we’ll talk about what WordPress redirects are and how to implement them. Let’s dive in!
What Is a Page Redirect?
A page redirect is a set of rules telling a browser to forward your visitors from the link they clicked to a different page. There are two outcomes for your end users when you redirect a page. They will either see a message that lets them know they are being redirected, or they will simply be forwarded without being notified.
If you’ve changed your domain, made updates to your permalinks, or redesigned your site, you’ll need to add redirects so your pre-existing content is still accessible to your readers and search engines. Think of it this way. When you move to a new home, you have to contact the post office and have your mail forwarded to your new address. Redirects work the same way, except instead of forwarding your mail, you are forwarding to a new webpage.
How to Redirect a Page in WordPress
WordPress offers various methods for page redirection. You can use a plugin, or make changes to your site’s .htaccess file. Which method you choose will depend on the type of redirect you need, your hosting provider’s settings, and your comfort level with making changes to a core file.
WordPress Redirect Plugins
The WordPress Plugin Directory offers many plugins for adding redirects to your site. When choosing a plugin for this purpose, be sure to research each one to make sure it’s well reviewed, widely used, and actively updated. Below, we’ll recommend some plugins that will help with each redirect scenario.
WordPress .htaccess Redirect
The .htaccess file is a configuration file that tells your server how to display pages from the WordPress root directory. You’ll need to check with your hosting provider before making changes to .htaccess, as it may have rules about what alterations you can make. If you have a plan here at WP Engine, we recommend that you use our Redirect Rules tool.
301 Redirects in WordPress
A 301 redirect is used to permanently forward one URL to another, unlike 302 redirects (which are temporary). This means search engines will default to the page at the new location, and index it appropriately. This type of redirect prevents your site from losing search engine rankings.
To create a 301 redirect in .htaccess, you will need to use a File Transfer Protocol (FTP) client to access the file on your server. We recommend FileZilla. Before you get started, make sure you have a backup of your site in place. Then, use FileZilla to navigate to your site’s root directory:
From here, download your .htaccess file. You’ll want to make a copy, in case you make a mistake and need to restore the original. Then at the top of the file, add the following line:
Redirect 301 /current-page.html http://www.yoursite.com/new-page/
This redirect will change your URLs from http://www.yoursite.com/current-page.html to http://www.yoursite.com/new-page (you’ll need to replace the placeholders with your site’s information). When adding your redirects, remember that you can only have one per line in the .htaccess file.
If you prefer to use a plugin instead, we recommend Redirection. This plugin is helpful for beginners, and can be used to forward any URL easily.
Server-Side Redirects
There are certain situations when you’ll need to place a 301 redirect at the server level, so it can be enforced across the entire site. These are most commonly used when redirecting from HTTP to HTTPS, or from a www to a non-www domain.
How to Redirect HTTP to HTTPS in WordPress
If you’ve installed an SSL certificate and successfully migrated your site to its new HTTPS domain, you’ll still need to create a server-side redirect. To do this in .htaccess, you’ll need to follow the steps above to locate and download the file. Once there, add the following code at the top of the page:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC]
This code changes every URL under your previous domain to a secure counterpart. If you’d prefer to use a plugin to do this, we recommend Really Simple SSL:
This plugin automatically detects your site’s settings and then configures it to run over HTTPS. As long as you have a valid SSL certificate, it will take care of the rest for you.
Once you install and activate the plugin, you’ll get a notice asking you to enable SSL. Click the button, and log back into your account. That’s it!
WWW to Non-WWW Redirection
To redirect your pages to non-www URLs, you’ll need to apply the change at the full site level. This redirect helps you avoid page duplication and poor user experience. To redirect www to non-www in your .htaccess file, you’ll need to enter the following lines at the top:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
If you’re looking for a plugin that can help you do this, we again recommend Really Simple SSL. However, there’s also a WP Rocket Helper plugin available through GitHub that is highly recommended by the developer community. This plugin enables you to redirect www to non-www and vice versa, by adding the correct code for you.
How to Redirect a Domain in WordPress
If you’re moving your WordPress site to an entirely new domain, you’ll need to perform a domain redirect to avoid losing your content’s SEO. These instructions assume you’ve backed up your site and moved it to its new domain.
To perform this redirect, open up your .htaccess file, and add this code to the top:
#Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.newsite.COM/$1 [R=301,L]
Use your new domain in place of newsite.com, and then save the file. You can also use any of the above-mentioned plugins to accomplish this task, as long as you activate it on your old site
Of course, WP Engine can eliminate the need to use any of these plugins or make .htaccess changes yourself. Not only do we provide our easy-to-use Redirect Rules tool to help you manage your redirects, our support team is always available to assist. Learn more about what we offer for our WordPress users by checking out our hosting plans!