Redirecting Most, but Not All, of Your Posts to a New Domain with WordPress

Generic redirects work, but if you need to post new content, you need a little strategy and some regex tricks to open a “hole” for new content.

My vanity site, riceball.com, is being changed to host content about riceballs, so all the posts were moved to this site, technote.fyi. This was simple enough: use a regex to redirect everything. I used the Redirection plugin.

URL regex to match: ^/(.*)$
URL redirects to: http://technote.fyi/$1

I had one exception, which was to an external site:

/programming/wordpress/unix-text-file-database/using-muriatic-acid-pool-acid-clean-toilet.html
http://bits.greenslocal.org/articles/how-to-use-muriatic-acid-to-clean-a-toilet/

To make that exception override the generic regex, I set the “Pos”ition to a lower number.

Everything is good, except there’s one article I want to preserve, about riceballs!

http://riceball.com/blog/2019/04/18/friday-april-19-is-national-rice-ball-day-in-japan/

Carving Out Space for New Content

This is going to be tricky. There doesn’t seem to be a way to carve out an exception for this URL.

The solution is to change the permalink structure for the site, so this page gets a new permalink. I’ll put all the new posts into /posts/.

Note that changing the permalink affects only the Post URLs (the blog part of the site); it won’t affect the Page URLs.

Then, instead of a single regex redirect for all the articles, create redirects for subdirectories for the old URLs.

The old URLs have these top level subdirectories (written as regular expressions):

^/category/(.*)$
^/tag/(.*)$
^/blog/(.*)$
^/chatter/(.*)$
^/code/(.*)$
^/programming/(.*)$
^/sysadmin/(.*)$

Establish rules to redirect each of those URLs.

http://technote.fyi/blog/$1
etc.

Disable the original, generic rule.

This URL should work: National Riceball Day

Endgame

Then, wait a few hours, or days, for URLs to redirect, and see the 404 errors stack up.

Riceball.com is so old, and has been through so many changes, and different content management systems, that hundreds of stray URLs are still out there.

After catching enough 404 errors to be able to create redirects for most of the site, I’ll convert the redirect rules into redirection rules for mod_rewrite, and put them into the .htaccess file, for faster and less CPU-intensive redirections.

Leave a Reply