1

I am using spring-cloud-starter-gateway (Hoxton.SR5) When I try to call my application with slash it works. http://localhost/myapp/

But when I call without slash http://localhost/myapp it is getting redirected to port on which myapp is running.

http://localhost:96/myapp/

Here's the yml

spring:
  application:
    name: gateway
  cloud:
    gateway:
      routes:
      - id: myapp
        uri: http://127.0.0.1:96
        predicates:
        - Path=/myapp, /myapp/**

server:
  port: 80

What am I doing wrong here. Any help be appreciated.

3
  • gateway doesn't redirect at all by default. can you confirm that the app running on port 96 is doing the redirect? Commented Jun 8, 2020 at 16:48
  • @spencergibb - i checked, app is not doing the redirect. The gateway works fine with trailing slash. Any thoughts? Commented Jun 8, 2020 at 16:56
  • @spencergibb - double checked. you're right, app is doing the redirect. Commented Jun 8, 2020 at 17:07

2 Answers 2

2

I was facing similar issue in an angular application with Spring. In my case for the page to load properly I need to add trailing slash to the URL. The below configuration redirects /myapp to /myapp/.

Note: It's observed that any mappings that start with /myapp MUST be present after this route.

Since Location header supports relative path as stated in HTTP 1.1, this also made it easy to exclude hostname in RedirectTo.

- id: myapp
  uri: no://op
  predicates:
  - Path=/myapp,false
  - Method=GET
  filters:
  - RedirectTo=302,myapp/
Sign up to request clarification or add additional context in comments.

Comments

1

I also faced the same issue but found that Path=/myapp/** should work in all cases be it /myapp or /myapp/4. If you are getting 500 or 404 sometimes, please check if you are using a loadbalanced url (as in my case).

2 Comments

Redirect was due to trailing slash in tomcat redirect-context-root: false
As mentioned above, add this property in your app redirect-context-root: false

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.