WordPress: Find and Replace All Permalinks In Your Database using Regular Expressions (Example: /YYYY/MM/DD)

With any site that spans over a decade, it’s not uncommon that there are many changes made to the permalink structure. In the early days of WordPress, it wasn’t uncommon for the permalink structure for a blog post to be set to a path that included the year, month, day, and the slug of the post:
/%year%/%monthnum%/%day%/%postname%/
Aside from having an unnecessarily long URL, there are a couple of other issues with this:
- Potential visitors see a link to your article on another site or on a search engine and they don’t visit because they see the year, month, and day that your article was written. Even if it’s an amazing, evergreen article… they don’t click on it because of the permalink structure.
- Search engines may deem the content as unimportant because it’s hierarchically several folders away from the home page.
When optimizing our clients’ sites, we recommend that they update their post permalink structure to:
/%postname%/
Of course, a major change like this can cause setbacks, but we’ve seen that over time, the advantages far outweigh the risks. Remember that updating your permalink structure does NOTHING to redirect visitors to those old links, nor does it update internal links within your content.
How To Update Your Permalinks In Your WordPress Content
When you make this change, you may see a drop in your search engine ranking on those posts because redirecting the link may reduce the authority of backlinks. One thing that can help is to properly redirect traffic coming to those links AND to modify the links in your content.
- External Link Redirects – you must create a redirect on your site that searches for the regular expression pattern and properly redirects the user to the appropriate page. Even if you fix all internal links, you’ll want to do this for external links that your visitors are clicking on. I’ve written about how to add a regular expression (regex) redirect in WordPress and specifically about how to do the /YYYY/MM/DD/ redirect.
- Internal Links – after you update your permalink structure, you may still have internal links in your existing content that point to the old links. If you don’t have redirects set up, they will result in you getting a 404 not found error. If you have redirects set up, it’s still not as good as updating your links. Internal links have been proven to benefit your organic search results, so reducing the number of redirects is a great step in keeping your content clean and accurate.
At issue here is that you need to query your posts data table, identify any pattern that looks like /YYYY/MM/DD, and then replace that instance. This is where regular expressions come in perfectly… but you still need a solution to iterate through your post content and then update the instances of the links – without messing up your content.
Thankfully, there’s a great solution out there for this: WP Migrate Pro. With WP Migrate Pro:
- Select the table you wish to update, in this case, wp_posts. By selecting a single table, you minimize the resources that the process will take.
- Insert your regular expression. It took some work for me to correct the syntax, but I found the generative AI engines do a fantastic job. In the Find field, insert the following (customized for your domain, of course):
/martech\.zone\/\d{4}\/\d{2}\/\d{2}\/(.*)/
- The (.*) is a variable that’s going to capture the slug from the source string, so you have to add that variable to the Replace string:
martech.zone/$1
- You must click on the .* button to the right of the replace field to let the application know that this is a regular expression find and replace.

- One of the nicest features of this plugin is that you can actually preview the changes before executing them. In this case, I could immediately see what edits were going to be made to the database.

Using the plugin, I was able to update 746 internal links in my content within a minute or so. That’s a heck of a lot easier than looking each link up and trying to replace it! This is just one small feature in this powerful migration and backup plugin. It’s one of my favorites and it’s listed on my list of best WordPress plugins for business.