Rewrite + splat turns into redirect

I’m trying to create a rewrite to another service, using a TOML file. When I don’t use a splat it works, however when I do use a splat its turned into a 301.

This works as expected, proxies the request, and returns a 200:

[[redirects]]
  from = "/test"
  to = "http://otherserice.com/test"
  status = 200

This does not work as expected, returns a 301:

[[redirects]]
  from = "/test/*"
  to = "http://otherserice.com/test/:splat"
  status = 200

Any ideas?

Hi, @tkrein, that rule looks like it should work as written.

Would you please send us an actual URL which should proxy (200 redirect) but is doing a 301 redirect instead? If we can reproduce the issue we can find out why it is happening.

Yea, here’s actual builds. I tried both with _directs and TOML. The _redirects is below, I can’t post the TOML versions because there’s a limit to how many links I can post.

For all of them, the test is to goto /test off the build url, in the browser or CURL.

A build, using _redirects, with a splat, and doesn’t work as expected (get a 301)

A build without a splat, using _redirects, that works (but we want splat support):

Hi, @tkrein, I also replied in the other channel where this was asked about. The issue is that the redirect with the splat goes to /test/ (instead of /test) and the redirect 301 status is being returned by the end system.

Also, I think the solution is to change the ordering of the rules from this:

[[redirects]]
  from = "/test/*"
  to = "http://homeroom-7254153.hs-sites.com/test/:splat"
  status = 200
  force = true

[[redirects]]
  from = "/test"
  to = "http://homeroom-7254153.hs-sites.com/test"
  status = 200
  force = true

To this:

[[redirects]]
  from = "/test"
  to = "http://homeroom-7254153.hs-sites.com/test"
  status = 200
  force = true

[[redirects]]
  from = "/test/*"
  to = "http://homeroom-7254153.hs-sites.com/test/:splat"
  status = 200
  force = true

Putting the non-splat rule first should get required behavior. If not, please let us know.

Thanks, that does seem to fix it!

I had been trying the two in isolation, which didn’t work, and I do think I tried them both being there as well, but probably had them in the reverse order (I wasn’t thinking about the order).

Maybe you can forward this to the documentation team, as I think it would be common that a wildcard path should be paired with the slash only as well.

Again thank you!

1 Like