Remove Trailing Slash with Transform Rules URL Rewrite

Hi!

Can someone help me how can I remove the trailing slash from all urls with the Transform Rules URL Rewrite feature?

https://www.example.com/url1/ to https://www.example.com/url1
https://www.example.com/url2/ to https://www.example.com/url2
https://www.example.com/url3/ to https://www.example.com/url3

I’ve already set it in wordpress, also in htaccess, but somehow there can be slashes again, they are not removed (redirected to the correct url without a slash) so I would like to do it with Transform Rules as it would be a more reliable solution.

How did you set this in WordPress? I have a WP site with Permalinks set to a Custom Structure with no trailing slash, and browsing the site shows no trailing slash.

At the Permalink settings. It used to work well, but now I’ve seen a few urls in analytics with a trailing slash at the end. I’ve wondered, then I tried it and they are not removed. Also I can enter any url with 4-5 trailing slashes at the end and the website and urls are working without any problem. So it’s weird.

It wouldn’t surprise me if you saw trailing slashes in Analytics, as that will show any request to your site.

If I add a trailing slash, WordPress redirects to no trailing slash.

It’s also not a good idea to use URL Rewrite to remove these before they get to your server, because SEO will see that as two different URLs with the same content.

Now it seems that sometimes Wordpress redirects the urls (to the ones without a trailing slash) and sometimes don’t. Don’t know why. I’ve also have a “Cache everything” Page Rule.

What would be the best option to eleiminate trailing slashes with Cloudflare?

https://community.cloudflare.com/search?q=remove%20trailing%20slash

None of the threads solve this issue using Page Rules or Redirect Rules.

Sorry! My bad!

The “trailing slash redirect” rule was missing from .htaccess.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

Is it possible to do it with Cloudflare Rules, though?
I assume it would reduce the latency.

Yeah, it would be better, but haven’t managed to do it. I rather rely on Cloudflare too :slight_smile: