How to redirect trailing slash to non-trailing slash URL in Cloudflare?

I recently migrated a WordPress blog with 100+ posts to Hyvor Blogs. In WordPress, all posts had a trailing slash /. For example, https://example.com/post/. However, posts in Hyvor Blogs does not have a trailing slash, even though its possible to configure this.

But, I like the way URL looks without a trailing slash. In my mind, I see /post/ as a directory, and /post as an actually resource (makes more sense I guess).

First, go to Redirect Rules.

Cloudflare Redirect Rules

Then, add a rule with the following configuration.

Set up non-trailing slash redirect

Here, all the incoming requests that have an URI Path that ends with / are matched. Then, it is dynamically redirected to the non-trailing slash page. substring(http.request.uri.path, 0, -1) simply removes the last character. 301 means a permanent redirect.