Header Shadow Image

301 Redirects For WordPress using RedirectMatch | WordPress SEO

Sometime back we've changed the links on this post from the /WordPress/YEAT/MONTH/DAY/[POST NAME] to something a bit shorter like /wp/[POST NAME].  Basically we took our earlier URL's and changed them up.  That's good and bad news.  The good because the links are shorter and since they already have a date, there really wasn't much sense in having them in the URL. The bad because everything that points to this site elsewhere will get a 404.  Here's a sample URL:


and the new URL.  


So how do we tell Google and other search engines to permanently redirect?

First, we'll let the search engines know through some handy regular expressions, where to point the old links.  This is OK and is typically a patch solution because Google and other search engines won't follow too many of these.  Unfortunately, the patch solution is the only one.

RedirectMatch 301 ^/(WordPress)/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ /wp/$5
RedirectMatch 301 ^/(wordpress)/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ /wp/$5
RedirectMatch 301 ^/(wp)/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ /wp/$5

RedirectMatch 301 ^/(WordPress)/([0-9]{4}/[0-9]{2}/.*)$ /wp/$2
RedirectMatch 301 ^/(wordpress)/([0-9]{4}/[0-9]{2}/.*)$ /wp/$2

RedirectMatch 301 ^/(WordPress)/(tag/.*)$ /wp/$2
RedirectMatch 301 ^/(wordpress)/(tag/.*)$ /wp/$2

RedirectMatch 301 ^/(WordPress)/(category/.*)$ /wp/$2
RedirectMatch 301 ^/(wordpress)/(category/.*)$ /wp/$2

RedirectMatch 301 ^/(WordPress)/(.*)$ /wp/$2
RedirectMatch 301 ^/(WordPress)$ /wp
RedirectMatch 301 ^/(wordpress)/(.*)$ /wp/$2
RedirectMatch 301 ^/(wordpress)$ /wp

Next, we'll handle the pages that have a real 404 for not being found at all or some erronous URL's out there that never existed.  We want an informative page to tell the reader what to do.  So we create some error page redirects to hopefully direct the user properly or at least to a page where they can search:

# Error Redirection
ErrorDocument 400 http://microdevsys.com/wp/available-through-search/
ErrorDocument 401 http://microdevsys.com/wp/available-through-search/
ErrorDocument 402 http://microdevsys.com/wp/available-through-search/
ErrorDocument 403 http://microdevsys.com/wp/available-through-search/
ErrorDocument 404 http://microdevsys.com/wp/available-through-search/
ErrorDocument 405 http://microdevsys.com/wp/available-through-search/
ErrorDocument 406 http://microdevsys.com/wp/available-through-search/
ErrorDocument 500 http://microdevsys.com/wp/available-through-search/
ErrorDocument 501 http://microdevsys.com/wp/available-through-search/
ErrorDocument 502 http://microdevsys.com/wp/available-through-search/
ErrorDocument 503 http://microdevsys.com/wp/available-through-search/
ErrorDocument 504 http://microdevsys.com/wp/available-through-search/
ErrorDocument 505 http://microdevsys.com/wp/available-through-search/

That also goes into your .htaccess file. The result is that the reader will be redirected to a page where they at least have some options:


And this page tells the reader:

Available Through Search


OOPS!  Looks like we moved the page under another link.  Please use the search option to the right to navigate to the content. (404)

We couldn't find the page you are looking for or you have stumbled on the 40X (400, 401, 402, 403, 404 … )  or 500 (500, 501, … ) error message.  Most likely the page had moved under another link.  Please use the search to the right of this page to try and find the content in that manner.  

This link on HTML Status Code Definitions may help as well.  



Hope you found this usefull.  Feel free to pot a comment and let us know your experience.


Leave a Reply


  Copyright © 2003 - 2013 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License