Istio URI match with Rewrite

Getting 404 error when Virtual service with multiple URI match and rewrite URL created.
Below is the example.
We have one microservice A, we want whenever there is any call to https://hostName/serviceA/ it should get overwrite with https://hostName/ and whenever there is any call to
https://hostName/serviceA/scheme/default/ it should get overwrite with https://hostName/scheme/default

Below is the snippet of Virtual Service.

- name: service-A
    match:
    - uri:
        prefix: /serviceA/
      ignoreUriCase: true
    rewrite:
      uri: /
    headers:
      request:
        add:
          Cache-Control: "max-age=0, no-cache, no-store, must-revalidate"
          Pragma: "no-cache"
          Expires: "-1"
    corsPolicy:
      allowOrigins:
      - exact: "*"
      allowMethods:
      - POST
      - GET
      allowCredentials: true
    route:
    - destination:
        host: service-A
        port:
          number: 8080
  - name: themes-service-A
    match:
    - uri:
        prefix: /serviceA/scheme/default/
      ignoreUriCase: true
    rewrite:
      uri: /scheme/default
    headers:
      request:
        add:
          Cache-Control: "max-age=0, no-cache, no-store, must-revalidate"
          Pragma: "no-cache"
          Expires: "-1"
          add_header: "more_clear_headers server"
    corsPolicy:
      allowOrigins:
      - exact: "*"
      allowMethods:
      - POST
      - GET
      allowCredentials: true
    route:
    - destination:
        host: service-A
        port:
          number: 8080

But whenever we hit https://hostName/serviceA/scheme/default/ it gives a 404 error and we can see from the developers tool that the request goes to /serviceA//scheme/default/

But all request sent to https://hostName/serviceA/ gets 200 response.

Need your help to solve this issue

Hi,

Switch the order of your two routes – the themes-service-A should come first and then the service-A. The reason for it is because Envoy processes the routes in order, so when you make a request to /serviceA/scheme/default, it gets matched to the /serviceA/ prefix.

2 Likes

Thanks @peterj It worked

1 Like