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.
There a number of different ways to manage redirects with a WordPress site, some are implemented automatically by WordPress while others require webmaster input.
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.
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.
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/.
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.
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
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.