Redirects without trailing slash how to

I am trying to figure out how to handle single page redirects to a complex target.

I am trying to do something like this:

https://{default}/foo-detail/:
  type: upstream
  upstream: foo-detail:http

https://{default}/foo:
  type: redirect
  to: https://{default}/foo-detail/A/B/C/some-page.html

The path /foo is not a whole path with lots of things underneath it, just a simple target that sends the user to a specific page. On the other hand, /foo-detail is a really path with lots of things underneath it.

This mostly works, except that if I do curl https://example.com/foo/ (note the trailing /), then it redirects to some-page.html/, which does not exist.

How can I get /foo to be “just foo, do not pass the rest along”?

0

Comments

1 comment
Date Votes
  • I think you might be running into this piece concerning trailing slashes.

    If I’m understanding your goals correctly, you’ll probably need to add partial redirects on the route entry for https://{default}/:
    You can then use regular expressions to be more accurate on what you do/don’t want redirected.

    https://{default}/foo-detail/:
      type: upstream
      upstream: foo-detail:http
    
    https://{default}/:
        # ...
        redirects:
            expires: 1d
            paths:
                '^/foo(?!-detail)':
                    to: 'https://{default}/foo-detail/A/B/C/some-page.html'
                    regexp: true
    

    This is at least one possible way to do it. I would need to see the rest of your routes.yaml to be able to suggest the optimal method.

    0

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post