Don’t Lose A Single Link! Permalink Redirects Save the Day

A recent client project required converting an HTML site to WordPress, to merge with an existing WordPress blog. Whew! That was a challenge. On top of it all, the new WordPress site used a static homepage with a separate blog page. This proved problematic when I tried to set up the permalink redirects so that links across the internet weren’t broken.

The HTML site was at http://examplesite.com, with the blog at http://examplesite.com/blog.

It took me a while to figure out how to get the redirects to work so that the old blog posts (there were hundreds) would redirect to the new blog posts.  Just adding a redirect to redirect any URLs with /blog didn’t work, as the new blog page was ALSO examplesite.com/blog, but all the posts were examplesite.com/month/day/postname. I also needed to ensure that the old WordPress site, examplesite.com/blog, redirected to the new BLOG page of the new site. When I added that redirect, and set it so that the new post permalinks included /blog/, everything redirected to the main blog site. Not ideal.

Everything I tried gave me errors & redirect loops until I finally stumbled on this solution:

#redirect old to new
RewriteEngine On
RewriteRule ^/blog/(.*)$ http://www.examplesite.com/articles/$1 [R=301,L]
Redirect 301 /blog http://www.examplesite.com/articles

In the WordPress permalink settings, I decided to use /articles/ as part of the permalink for all blog posts, and also set the Blog page permalink to /articles as well. Once that was completed, I implemented the code above. Now, all of the old permalinks, http://examplesite.com/blog/month/day/postname are properly redirecting to http://examplesite.com/articles/month/day/postname, and the main blog URL (which, remember, was an independent WordPress install previously, and examplesite.com/blog was the home URL) redirects to http://examplesite.com/articles.

This also allowed me to set up individual redirects for the HTML pages from http://examplesite.com to redirect to the appropriate new locations on the WordPress site, leaving the root as-is.

Amazing how four little lines of code can fix a huge problem.

There are no comments yet. Be the first and leave a response!

Leave a Reply


Wanting to leave an <em>phasis on your comment?

Trackback URL http://rentageekmom.com/dont-lose-a-single-link-permalink-redirects-save-the-day/trackback/