Redirect rule for changeing permalink structure in Word Press

Ok so I have recently decided I want to repost some of my old blog posts, unfortunately, my permalink structure is www.mysite.com.au/month/year/title. I have been told that I could lose all my “link juice” (as they are calling it these days) when I re-post as the month/year part of my permalink will update.

So my plan was to change my permalink structure for posts over to www.mysite.com.au/title, and see if it was possible to set up a 301 redirect rule in Cloudflare to auto-forward (www.mysite.com.au/month/year/title) to (www.mysite.com.au/title).

This is proving to be a pain in the bum as I can’t think of a rule that would suit all cases!

Now I have noticed that Word Press does some auto redirecting (despite all the plug-ins that say it doesn’t) but I’m not 100% sure how that works either. so any advice would be sweet!

If you just intend to re-post as it is, you could change the post’s date to its original publication date on WordPress dashboard > Posts. A Quick Edit action allows you to do it.

But if you intend to move to a Permalink structure without /year/month/ segment, you’d need either:

  1. a Single Redirect that uses regex, which is available on Business or Enterprise plans, or
  2. a Bulk Redirect, with a list matching each old URL with its new version. Bulk Redirect is available to all plans.

For the single redirect, you could adapt the rule from this example:

2 Likes

Gaah!!
Thanks heaps for that response, very helpful! :slight_smile:

Although I just spend the better part of an hour making the .csv for bulk uploading to find out there is a limit of 20 redirects and I have 84 articles so far. :frowning:

The rule for single redirects kinda confused me, I get that the locale info is just an example and that’s similar to my issue with the dates, but what is this ( * Value: ^/[A-Za-z]{2}-[A-Za-z]{2}/) all about?

Could you please elaborate a little on that for me?

A bit too short, isn’t it? You can always create a Page Rule with a matching wildcard, and hope and cross your fingers, that Cloudflare may decide to expand the availability of Redirect Rules when it comes time to deprecate Page Rules.

Source: URL: /20*/*/*/
Target URL: /$3/

For a more permanent solution, you can create Bulk Redirects to your most visited pages, and let the origin do the remaining redirections.

This is about Regular Expression, and you can have fun learning it with online tools such as regex101.com and GitHub - ziishaned/learn-regex: Learn regex the easy way.

In your case,
^/[A-Za-z]{2}-[A-Za-z]{2}/
would start with something like [must try]
^/20[0-9]{2}/[0-9]{2}/
to match
/20[any 2 digits]/[any 2 digits]/

2 Likes

Oh, thats cool! The regular expressions thing is bringing back some memories from uni, Thanks heaps thats super helpful! I guess now I just need to decide if having a business account is worth the money!

1 Like

Just checking because I’m paranoid: does this look right?

It’s a bit more complex than that.

In the matching regex, you need to have a capture group to copy the post-name part of the URL and pass it on to the target URL:

^/20[0-9]{2}/[0-9]{2}/(.+)$

Then you need to use the concat() as well as the regex_replace function to put together a full URL:

Dynamic:
concat("https://",http.host,regex_replace(http.request.uri.path,"/20[0-9]{2}/[0-9]{2}/(.+)/","/${1}/"))

It took me a long time to make this work, and I still can’t figure out why an ending slash was needed in the final URL formula, when the capture group from the matching regex should match 1 or more characters—in regex represented by (.+)— up until the end $ of the element—and the URI Path element includes a trailing slash in most /YYYY/MM/ permalink structures. lol forget it, I was thinking the capture group from the matching regex, which is different than the capture group of the regex_replace.

You can try with some examples here (as as you’ll see, there are some differences between Cloudflare Regex and the GoLang vertion of regex it is based on.:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.