One-Off Script: Fix Yoast SEO Redirects When Switching Permalink Structure

If you use Yoast SEO to manage redirects and you change your permalink structure you may need to update a large amount of your redirects.

Here is a small simple script to help with that. This was made for when you switch from https://www.sethryder.com/2018/10/31/sample-post/to https://www.sethryder.com/sample-post/. If you are switching to something else it should be easy to modify, you will just need to update the regex in the preg_replace.

The two rows you will want to run through this script in your database are the wpseo-premium-redirects-export-plainand the wpseo-premium-redirects-basein wp_options. I assume they may vary if you are not using the premium version of the plugin.

This script will take the serialized options in the database (that you copy into the expected text files) and go through them and remove/update the redirect links. Once finished it writes them to the new files and you can replace the rows in your database.

Leave a Reply

Your email address will not be published. Required fields are marked *