Cloudflare rule: strip trailing slash

pagerules

#1

I’m able to remove trailing slashes by having two redirect rules:

  • No query string: https://foo.com/*/ -> https://foo.com/$1
  • Yes query string: https://foo.com/*/?* -> https://foo.com/$1?$2

But I’d prefer to do this with one rule.

I tried:

  • No/Yes query string: https://foo.com/*/\??* -> https://foo.com/$1$2

But I can’t seem to get it working.
Any ideas on something else to try?


#2

If you’re running Apache, you might be able to do it with .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect to non-trailing slash
RewriteRule ^(.*)/$ /$1 [R=301,L]