Content MarketingSearch Marketing

WordPress: Remove and Redirect A YYYY/MM/DD Permalink Structure with Regex and Rank Math SEO

Simplifying your URL structure is a great way to optimize your site for a number of reasons. Long URLs are difficult to share with others, can get cut off in text editors and email editors, and complex URL folder structures can send the wrong signals to search engines on the importance of your content.

YYYY/MM/DD Permalink Structure

If your site had two URLs, which one would you think has provided the article with higher importance?

  • https://martech.zone/permalink-optimization OR
  • https://martech.zone/permalink-optimization

One of the default setups for WordPress is to have a permalink structure on the blog that includes the yyyy/mm/dd within the URL. This isn’t ideal for a couple of reasons:

  1. Search Engine Optimization (SEO) – As discussed above, the hierarchy of the site is basically showing search engines that the content is 4 folders away from the home page… so it’s not important content.
  2. Search Engine Result Page (SERP) – You may have a fantastic article on your site that you wrote last year but that’s still valid. However, other sites are publishing more recent articles. If you viewed a date structure that was a year ago in the search engine result page (SERP), would you click the older article? Probably not.

The first step to take is to update Settings > Permalinks in WordPress admin and just make your permalink the /%postname%/

WordPress Settings Permalink

This; however, would break all of your existing post links on your blog. After having your blog live for a while, it’s not fun adding redirects for every one of your old articles. That’s okay because you can utilize a Regular Expression (Regex) to do this. A regular expression looks for a pattern. In this case, our regular expression is:

/\d{4}/\d{2}/\d{2}/(.*)

The expression above breaks down as follows:

  • /\d{4} looks for a slash and 4 numeric digits representing the year
  • /\d{2} looks for a slash and 4 numeric digits representing the month
  • /\d{2} looks for a slash and 4 numeric digits representing the day
  • /(.*) captures whatever is at the end of the URL into a variable that you can redirect to. In this case:
https://martech.zone/$1

This is how it looks within the Rank Math SEO plugin (listed as one of our favorite WordPress plugins), just don’t forget to ensure the type is set to Regex with the dropdown:

rank math seo redirects

Removing Blog, Category, or Category Names or Other Terms

Removing Blog – If you had the term “blog” within your permalink structure, you can utilize Rank Math SEO’s redirections to populate

/blog/([a-zA-Z0-9_.-]+)$

Notice on this, I didn’t use the (.*) option since that would create a loop if I had a page that was just /blog. This requires that there’s some kind of slug after the /blog/. You’ll want to redirect this just as above.

https://martech.zone/$1

Removing Category

– To remove category from your slug (which is there by default) deploy the Rank Math SEO plugin which has an option to strip category from the URL structure in their SEO settings > Links:

Rank Math Strip Category from Links

Removing Categories – If you had categories, you’ll want to be a bit more careful and create an array of the exact category names so you don’t accidentally create a circular loop. Here’s that example:

/(folder1|folder2|folder3)/([a-zA-Z0-9_.-]+)$

Again, I didn’t use the (.*) option since that would create a loop if I had a page that was just /blog. You’ll want to redirect this just as above.

https://martech.zone/$1

Disclosure: Martech Zone is a customer and affiliate of Rank Math.

Douglas Karr

Douglas Karr is CMO of OpenINSIGHTS and the founder of the Martech Zone. Douglas has helped dozens of successful MarTech startups, has assisted in the due diligence of over $5 bil in Martech acquisitions and investments, and continues to assist companies in implementing and automating their sales and marketing strategies. Douglas is an internationally recognized digital transformation and MarTech expert and speaker. Douglas is also a published author of a Dummie's guide and a business leadership book.

Related Articles

Back to top button
Close

Adblock Detected

Martech Zone is able to provide you this content at no cost because we monetize our site through ad revenue, affiliate links, and sponsorships. We would appreciate if you would remove your ad blocker as you view our site.