<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>

<p>This fragment</p>
<pre class="lang-yaml prettyprint-override"><code>    - uri:
        prefix: &quot;/api/cities/{city_id}/tours&quot;
    - uri:
        prefix: &quot;/api/countries/{country_id}/cities&quot;
</code></pre>
<p>will be taken literally. The <code>{city_id}</code> and  <code>{country_id}</code> will not be replaced with your custom ID. At this point, istio will look for a prefix that reads literally <code>/api/cities/{city_id}/tours</code> or <code>/api/countries/{country_id}/cities</code>, which doesn't exist (you get error 404). If you want to match the expression to your custom ID you have to use a regular expression. Look at <a href="https://istio.io/latest/docs/reference/config/networking/virtual-service/#StringMatch" rel="nofollow noreferrer">this doc</a>. There you will find information about the capabilities of the StringMatch: <code>exact</code>, <code>prefix</code> or <code>regex</code>. You can find the syntax of the regular expressions used in istio <a href="https://github.com/google/re2/wiki/Syntax" rel="nofollow noreferrer">here</a>.</p>
<p>Summary:
You should change <code>prefix</code> to <code>regex</code> and then create your own regular expression to match your custom ID. Example:</p>
<pre class="lang-yaml prettyprint-override"><code>    - uri:
        regex: &quot;/api/cities/[a-zA-Z]+/tours&quot;
    - uri:
        regex: &quot;/api/countries/[a-zA-Z]+/cities&quot;
</code></pre>
<p>In my example, there are only letters (upper or lower case) in the ID. Here you have to create your own regular expression based on <a href="https://github.com/google/re2/wiki/Syntax" rel="nofollow noreferrer">this documentation</a>.</p>
