Managing 301 Redirects in WordPress

A 301 redirect is the HTTP status code returned by your browser when a web page is requested pointing the browser to go to a different location. The status code everyone will be most familiar with is a 404 which indicates that the requested page could not be found. The two main types of redirect are 301 and 302 the difference on the surface is minor but important, a 302 is a temporary redirect while a 301 is permanent. While the average user is unlikely to notice the difference search engines treat them very differently; a 301 passes SEO value (or ‘PageRank’) on to its redirect target while a 302 does not.

Other forms of redirect include Meta Refresh where the redirect is handled on a page rather than on a server level and 307 which is a HTTP 1.1 successor to a 302 redirect.
There are a number of reasons why you may need to permanently redirect to a new page including moving to a new domain, changing site structure or merging content, while a 302 would be used for displaying a clean URL for example when a session ID is used. The type of redirect a web page is using can be checked using a HTTP request and response header tool such as web-sniffer.net or a plugin for Firefox such as HTTP LiveHeaders.

Looking for hosting? WPEngine offers secure managed WordPress hosting. You’ll get expert WordPress support, automatic backups, and caching for fast page loads. Visit WPEngine.

Managing 301 Redirects in WordPress

There a number of different ways to manage redirects with a WordPress site, some are implemented automatically by WordPress while others require webmaster input.

Automatic Redirection

There are few different situations where WordPress will create a redirect for you, the first is if the slug element on a post or page is edited.

Managing 301 Redirects in WordPress

What is happening here is WordPress recording the old slug in the wp_postmeta table of the database (search for the _wp_old_slug in the meta_key column) the redirected slugs are stored in the meta_value column these are matched with a post_id which indicates the redirect target. If for some reason the default behaviour of WordPress’ redirects is incorrect or unwanted then this would be the part to edit.

The other instance where WordPress will implement at redirect is when the permalink structure of a site is changed. There can be issues where a post or page is made with the same name as the one that is redirecting to a new page.

Managing 301 Redirects in WordPress

Redirection Plugin

However, at times you may need to create your own redirects and a plugin such as the Redirection plugin can be used making the process of redirecting a page very simple.

Redirection also stores its redirect data in the database this time in the wp_redirection_items table which is created by the plugin. Once the plugin is installed and activated it can be found in the Tools menu of the WordPress dashboard. The plugin is filled in in the following format using the default settings:

The page to be redirected /oldpage/ and the redirect target http://example.com/newpage/.

Managing 301 Redirects in WordPress

.htaccess

The .htaccess (hypertext access) is a configuration file used by webservers. As well as supporting redirects it is used in URL rewriting and blocking IP addresses among other uses.

It can be found in the WordPress install root, if viewing with cPanel File Manager make sure the Show Hidden Files (dotfiles) option is checked otherwise it will not be visible. Of course before making any edits to the .htaccess file be sure to create a backup.

Managing 301 Redirects in WordPress

To implement a 301 redirect the code should be added to the top of the .htaccess file. It can be edited with a text editor such as notepad in similar format to the Simple 301 Redirects plugin.
Redirecting the entire site Redirect 301 / http://newsite.com/
Redirecting a WordPress page or a folder Redirect 301 /oldpage/ http://example.com/newpage/
Redirecting a file Redirect 301 /oldpage/image.jpg http://example.com/newpage/image.jpg

Managing 301 Redirects in WordPress

Ideally this is the method to use as a browser will read the .htaccess file before anything else and as such will be quicker than a page level 301 redirect. However, the redirect plugin is more user friendly and can simply be disabled on the off chance of something going wrong.

About the Author:

This post was written by Matt Russell CEO of WebHostingBuzz, who offer Shared, Reseller, and VPS web hosting services. You can follow them on twitter @webhostingbuzz or visit their site at http://www.webhostingbuzz.com.

Published December 14th, 2012 by

Looking for hosting? WPEngine offers secure managed WordPress hosting. You’ll get expert WordPress support, automatic backups, and caching for fast page loads. Visit WPEngine.

Join Our Newsletter!

Subscribe to our weekly newsletter chalked full of useful tips, techniques, and design goodies. We have 20,000+ loyal readers and counting! We’ll even send you a free e-book (Freelance Designer’s Guide to Multiple Income Streams) and a $10 discount on our most popular product the Freelance Starter Kit.

5 Responses

Comments are now closed on this post.

  • Paul, December 16, 2012

    I use the Redirection Plugin for this, mainly because it keeps a log of how many times the 301 took place.

  • Jacob, December 17, 2012

    Thanks for the information i am new to wordpress thanks a lot.

  • Mark Cody, February 11, 2013

    Great post and has helped me redirect a number of pages I have!

    Great Post

  • Payam Agha-Ghassem, June 4, 2013

    Really need help. I have a wordpress.com website and changed my url last week without knowing that google would not recognize the change. I need to redirect my old wordpress.com site with my new one.

    Can I use any of these options even though I just have a wordpress.com site instead of a wordpress.org site? Any help is appreciated. What can I do?

  • Julian, June 24, 2013

    I used to use the Redirection plugin, too, until I faced some strange situations for example that the homepage was redirecting to a post instead of showing the homepage. Fortunately this was solved using a simple tweak (removing the rules under WordPress redirects group).

    Now, I am in progress to understand how the redirect of images work, especially focused on SEO. In other words, I want to rename some of the images in my blog without losing the SEO visibility. I am wondering if the 301 redirect will have the same effect for images. What do you think?