How to set-up redirects in WordPress

Have you ever gone to a website and clicked a link and gotten a 404 error page instead? Super annoying! Either that page has been moved, or it’s been deleted. As a site owner, this sort of error will hurt your SEO and your search engine rankings. Instead of having your users get an error page, you need to set up a proper redirect to handle this situation.

This post is going to focus on the most common redirect, a 301 redirect. It allows you to tell search engines and your user’s browser that the page they are trying to reach has been permanently moved to a new location.

It is important to set up your redirects properly so that you don’t accidently cause an infinite redirect loop.

What you need to set up redirects

For WordPress installs, we recommend a plugin called “Redirection.” This plugin is well supported and even logs those pesky 404s for you so you can best manage those dead links.

If you are on a hosting platform, such as WPEngine which has a built in redirect system, so you will not need the plugin to handle these.

Setting up the redirect

Using regex (regular expression) can help simplify the process, whether you are needing to redirect a single page, or an entire subdirectory. Since we are only dealing with 301 redirects, we are going to keep things simple. For those who want to learn more about regex, here is a handy cheat sheet.

First off, the ^ symbol is your friend. It keeps you from needing to type or copy the entire URL over and over. So instead of typing the full domain, like https://standardbeagle.com/shop you can simply type ^/shop and the system understands it’s supposed to include everything prior to the front slash.

Here are some specific examples on how to use regex with redirects:

Purpose regex
Including entire directory except any subdirectories ^/shop/?$
Include all subdirectories ^/shop/.*
Include everything that contains a specific phrase ^/.*shop>
Match any sort of capitalization ^/(?i)shop

 

We recommend always setting your old posts or pages to draft since they have been indexed already by Google. Then, set he redirect up to go back to an archive page or even a homepage if you are not replacing the content. Or, set the redirect to the new page or post.