Trailing slash redirect leaks proxied location

Our site prestosql.io has a proxy configured for the /docs/* path. When a URL under this path is accessed without a trailing slash, Netlify redirects to the proxied site rather than proxying. For example, make a request to the following URL (note the lack of trailing slash):

Presto Documentation — Presto 0.284 Documentation

It results in a 301 to the proxied site:

https://prestosql.github.io/docs.prestosql.io/current/

I believe that Netlify is making an internal request without the trailing slash to the proxied site:

https://prestosql.github.io/docs.prestosql.io/current

The proxied site then responds to Netlify with a 301 redirect to add the trailing slash. However, Netlify is then forwarding that redirect URL as-is, rather than rewriting it to be local to the Netlify hosted website.

My expectation is that Netlify would return a 301 redirect to the following:

Presto Documentation — Presto 0.284 Documentation

Is there a way to make trailing slash redirects work properly in this situation?

Hi, @electrum, there is no trailing slash redirect occurring because you proxy this request to another service.

It is the other service returning the 301 response with the location of https://prestosql.github.io/docs.prestosql.io/current/.

Netlify will not modify the proxied response.

Note that the * in a redirect rule matches everything (including forward slashes) while placeholders do not match forward slashes.

If the missing forward-slash is only one level under docs, you can add a redirect rule before the existing rule to add the forward-slash when proxying.

The two rules would be the one below (in this order - the order matters):

[[redirects]]
  from = "/docs/:path"
  to = "https://prestosql.github.io/docs.prestosql.io/:path/"
  status = 200

[[redirects]]
  from = "/docs/*"
  to = "https://prestosql.github.io/docs.prestosql.io/:splat"
  status = 200

Note that won’t handle URLs with like this:

https://prestosql.io/docs/foo/current

If needed more than one rule can be use to extend this redirect behavior. For example:

[[redirects]]
  from = "/docs/:path1"
  to = "https://prestosql.github.io/docs.prestosql.io/:path1/"
  status = 200

[[redirects]]
  from = "/docs/:path1/:path2"
  to = "https://prestosql.github.io/docs.prestosql.io/:path1/:path2/"
  status = 200

[[redirects]]
  from = "/docs/*"
  to = "https://prestosql.github.io/docs.prestosql.io/:splat"
  status = 200

Would you please test this and let us know your results?