workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

Redirect source URLs ending in a slash should also match slashless URL

Open Hexstream opened this issue 3 years ago • 2 comments

What version of Wrangler are you using?

2.0.15

What operating system are you using?

Linux

Describe the Bug

It is widespread standard practice to redirect "directory" URLs not ending in a slash to the equivalent (canonical) URL ending in a slash, provided the directory index exists, and Cloudflare Pages already does so.

For instance, https://www.example.com/foo would typically redirect to https://www.example.com/foo/.

As such, I strongly believe that a redirect like /foo/ /bar/ 301, as well as redirecting /foo/ to /bar/, should also redirect /foo to /bar/.

Another argument is that, let's say you have a directory index at /foo/ (and /foo), and later you decide to delete it and replace it with a redirect with source URL /foo/, then the /foo URL (redirect to canonical) will not work anymore, which doesn't seem logical. And I think /foo would still work if you added the redirect but (deliberately or accidentally) did not delete the file, which is a bit weird.

For now, the workaround is to manually create that second redirect every time, but this seems gratuitously painful.

(Note that a redirect of /foo /bar/ 301 should NOT also redirect /foo/, because /foo.txt /bar.txt 301 clearly should not redirect /foo.txt/.)

Hexstream avatar Jun 22 '22 17:06 Hexstream

We did reproduce your issue, and it does make sense to fix. We've added to our backlog. Thanks! ☺️

nprogers avatar Sep 07 '22 14:09 nprogers

Awesome!! Thank you!!

Hexstream avatar Sep 07 '22 16:09 Hexstream

Now that Cloudflare Pages supports wrangler.toml, it would be easier to make the new behavior optional, retaining the old behavior by default for backwards compatibility.

How about also-redirect-slashless = true? The default would be also-redirect-slashless = false.

Hexstream avatar Apr 07 '24 17:04 Hexstream