Beginning with version 2.5, WordPress automatically handles many types of canonical redirects. A good example of this may be seen by typing your blog address into your browser both with and without the
www prefix. If you are using WordPress 2.5 or better, one of these versions of your blog URL will be immediately redirected to the other. The same type of automatic redirect may be seen for several other non-canonical URL variations, and is handled via PHP deep in the WordPress core.
Roads to nowhere
As good as WordPress happens to be at catching and redirecting non-canonical requests, there are other types of problem URLs that need to be fixed. Specifically, for permalink-enabled WordPress sites, the following three URLs result in dead-end, 404 (Page Not Found) errors:
The pages referred to by these URLs simply do not exist by default. Although these pages may not be requested by the average visitor, they are frequently visited by search engines such as Google. Whenever Google (or a curious visitor) attempts to load these pages, it encounters a dreaded 404 error.
This is not good for your visitors and statistics, and it certainly isn't helping your site's search engine position and page rank. Fortunately, an easy fix is available for those on Apache servers with access to either their
httpd.conf or root
If your site is located in the root directory of your domain, place this code into your root HTAccess file:
RedirectMatch 301 ^/tag/$ http://your-domain.com/ RedirectMatch 301 ^/search/$ http://your-domain.com/ RedirectMatch 301 ^/category/$ http://your-domain.com/
Likewise, if your site is located in a subdirectory called "blog", use this code instead, and place it into your site's root HTAccess file:
RedirectMatch 301 ^/blog/tag/$ http://your-domain.com/ RedirectMatch 301 ^/blog/search/$ http://your-domain.com/ RedirectMatch 301 ^/blog/category/$ http://your-domain.com/
Almost done! If you are using the first block of code (WordPress installed in site root), edit each of the three instances of "
http://your-domain.com/" to reflect the location to which you would like to redirect the dead-end URLs. For example, you may want to redirect all three URLs to your home page to extract any leftover rank juice.
Another option would be to redirect each URL to a similar page on your site. Anything is possible here; proceed according to your own strategy.
If you are using the second block of code, in addition to editing each instance of "
http://your-domain.com/", you will also need to edit each instance of "
/blog/" to match that of your actual subdirectory.
After editing the code and uploading to your site, you should now enjoy three less dead-end, 404 errors to worry about, while enjoying the SEO benefits of a cleaner, tighter WordPress-powered blog.