<p>I want to route through Istio virtual Service to my microservice. When I use <code>@RequestParam</code> based input in prefix or even in exact it throws <code>404</code> for <code>/api/cities/{city_id}/tours</code> but the rest works fine.</p>
<pre><code>apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: app
  namespace: nsapp
spec:
  gateways:
    - app-gateway
  hosts:
    - app.*.*.*
  http:
  - match:
    - uri:
        prefix: &quot;/api/cities/{city_id}/tours&quot;
    - uri:
        prefix: &quot;/api/countries/{country_id}/cities&quot;
    - uri:
        prefix: &quot;/api/countries&quot;
    route:
    - destination:
        host: appservice
        port:
          number: 9090
</code></pre>

N K Shukla
<p>Prefix matching matches literal strings.</p>
<p><code>/api/countries</code> also matches what you intend to match with  <code>/api/countries/{country_id}/cities</code></p>
<p><code>/api/cities/{city_id}/tours</code> however, does not work.</p>
<p>For more complex matching, you can use an exact and regex, as described in the <a href="https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPMatchRequest" rel="nofollow noreferrer"><code>VirtualService</code></a> documentation.</p>
<p>Maybe something like this (untested):</p>
<pre><code>exact: &quot;/api/countries&quot;
regex: &quot;/api/countries/[^/]*/cities&quot;
</code></pre>
