Cloudflare Pages: Disable Non-Trailing Slash 308 Redirect

On other Jamstack services, I could soft redirect a trailing slash URL to a non-trailing slash URL. For example:
https://example[.]com/test/ → https://example[.]com/test

Subsequently, requests to a non-trailing slash URL worked fine, responding with 200.

However, Cloudflare Pages seems to force all sites to use trailing slash URLs, making non-trailing slash URLs permanently redirect (308) to trailing slash URLs. This is problematic for SEO on sites that previously used non-trailing slash URLs. It also leads to two problematic scenarios:

  1. https://example[.]com/test will hard redirect (308) to https://example[.]com/test/ which will then soft redirect back to /test. That means all requests to non-trailing slash URLs are doubled.

  2. In some cases, pages will redirect infinitely resulting in a browser ERR_TOO_MANY_REDIRECTS.

If we could get the ability to disable 308 permanent redirects for non-trailing slash URLs, that would be great.

Hey! Have you found a solution to this? I’m facing the same problem.

1 Like

I ended up creating a hacky solution for this. Basically I used the fact that pages like /page/index.html are normalized to /page (without a trailing slash), so what I did was generate each page twice (one with a trailing slash and one without). Then, the page with a trailing slash will change the browser address bar from /page/ to /page.

Obviously this is not ideal since you’re dealing with duplicate content and getting 200 responses for both paths, which might hurt SEO. I also added link canonical meta tags which point to the non-trailing slash URL in case that helps.

1 Like