How to Redirect a URL in WordPress

How to Redirect a URL in WordPress

What is a Redirect

A redirect takes users from one URL to another – making the old page inaccessible and sending users to a different end URL. There are several different ways to implement redirects, each with their own pro’s and con’s. You typically redirect a URL in WordPress when you have a published a newer, better version of a post, OR an old post is no longer accurate and you want to send users to a page with current information.

What Type of Redirect Should You Use

There are several different types of redirects that you can use, each with pro’s and con’s but typically you will want to use a 301 (or Permanent) redirect. There are two main types of redirects: client side redirects and server side redirects. With a client side redirect, a user starts to load the original URL until the browser processes the code which says redirect the user to a new URL. These redirects happen in the user’s browser (client).

Alternatively server side redirects happen entirely on the server – as the name would suggest. When the user tries to load the original URL, the server says, actually we’re sending you over to this new page, instead of sending the user the content for the original page. Typically these redirects are better for SEO as they force search engines to access the right URL and are thought by most to pass more value from the original URL to the final URL.

Another consideration is that client side redirects typically do not pass referral data (where the user is coming from) to analytics, while server side redirects typically do pass referral data to analytics.

GroupRedirect TypeNotesCommon Uses
Client SideJavaScript RedirectExampleA/B testing software will often use a JavaScript Redirect to show users the new page
Client SideMeta RefreshExampleNot common
Server Side301 – PermanentBest for passing SEO value from one URL to anotherRedirecting old content to new content
Server Side302 – FoundThis used to be “Temporary” until 307 was introduced.Redirecting old content to new content
Server Side307 – Temporary Redirecting old content to new content

How to Redirect a URL in WordPress

The easiest way to redirect a URL in WordPress is to use a plugin. If you have an SEO plugin for your WordPress setup such as Rank Math or All in One SEO, you can add redirects in here. If you happen to be using Yoast SEO plugin, you will have to pay for the upgraded pro version of Yoast to be able to add redirects. Alternatively, you can get a dedicated plugin for redirecting URLs in WordPress. Alternatively, you can manually edit your .htaccess file and add in a redirect there.

Plugins to Redirect a URL in WordPress

For this section, we’ll look at leveraging both, an SEO plugin and a plugin specifically for redirecting URLs. While there are many plugins for SEO as well as creating redirects, they are typically fairly similar to the ones showcased here.

Using an SEO Plugin to Redirect URLs

Most popular SEO plugins will allow you to create redirects – including Rank Math, All in One SEO, and Yoast in their premium version (While Yoast used to include redirects in their free plugin, this feature has been moved to their premium product). Rank Math has a pretty extensive feature list and is our recommended SEO plugin and is what we’ll use to demonstrate how to redirect a URL in WordPress.

Start by navigating the the redirects section of Rank Math (“Redirections” in left navigation). Then click on “Add New” to create a new redirect.

how to redirect a URL in WordPress - Rank Math

From here, you’ll add the URL for the URL you’d like to redirect to the “Source URLs” field and then enter the destination URL (where you want to redirect the old URL to). A couple quick notes on this step:

  • You don’t need to add the domain (ex: https://wpadvisor.io/) before the page URL
  • By clicking “Add Another”, you can have multiple URLs redirect to the same final URL
  • There are many types of redirects you can use. “Exact” is shown below, but you can also choose “contains”, “ends with”, or “starts with”. More info here.
  • You can also specify the type of redirect – typically a 301 is what you’ll want to do as this passes the most SEO value.

Finally, it is worth noting that you can export and backup all of your redirects incase something goes wrong down the road.

how to redirect a URL in WordPress

Using a Redirection Plugin

While redirects are often a component of an SEO plugin, there are some plugins dedicated to redirecting URLs in WordPress. Redirection is one of the most popular WordPress redirect plugins. It is straightforward and easy to use. Start by setting up the plugin (tools > redirection) after installing and activating the plugin.

redirection - how to redirect a URL in wordpress

From here you’ll be able to setup a few universal settings such as whether to automatically create redirects when you change the URL of a post / page. Redirection can also log how many times your redirects have been hit and 404 errors which occur on your site.

After finishing up your initial setup, you’re ready to create your first redirect in WordPress. Go to the plugin settings and click “Add new redirection”. This screen will present several options. At the most basic level, you need to input the source URL and the target URL. You can also setup which type of redirect you want to use (defaults to 301) as well as matching types (similar to Rank Math).

The big difference in Rank Math vs Redirection is that Redirection allows for more control over how parameters are handled, which may or may not matter to you. This would most likely be important if you want to pass the initial referral parameters (primarily gclids or utms) to the final URL.

How to Redirect a WordPress Page Manually (Without a Plugin)

If you like to run a lean setup and want to avoid installing WordPress plugins, you can setup redirects in WordPress manually. To do this you will need to edit the .htaccess file directly or through a plugin which allows you to do this (which might defeat the purpose of not installing a plugin to do a redirect).

Note: This is not recommended. Incorrectly modifying your .htaccess file can take down your entire site. If you try this approach, make sure you have a current backup of your site.

For this example, we’ll redirect /initial-url to /final-url on the same domain. Open up your .htaccess file and add the following:

RewriteEngine On
 
Redirect 301 /initial-url /final-url

Please consult a WordPress developer to confirm that this will work for your setup before trying.

How to Redirect an Entire Site in WordPress

If you want to redirect an entire site in WordPress, you can use a plugin like Simple Website Redirect. Using this plugin you can specify what type of redirect you want to use (301, 302) and where you want your entire website to redirect to. You can also exclude paths (to allow some pages to remain accessible on the old site) as well as choose whether to preserve URL paths (ex: redirect /page-b to /page-b on the new domain).