title: istio: VirtualService rewrite to the root url
body: <p>I have an Istio 1.4.6 VirtualService with a match and a url rewrite defined as follows:</p>
  
  <pre><code>    match:
      - authority:
          prefix: example.com
        uri:
          prefix: /foo/bar
      rewrite:
        uri: /
      route:
      - destination:
          host: some-service
          port:
            number: 80
  
  </code></pre>
  
  <p>I would like a rewrite like follows:</p>
  
  <p>Traffic directed to <code>/foo/bar</code> or any subpath of that should be rewritten to <code>/</code> plus any subpath on <code>some-service</code>.</p>
  
  <pre><code>i.e.
  example.com/foo/bar -&gt; some-service
  example.com/foo/bar/subpath -&gt; some-service/subpath
  example.com/foo/bar/subpath/anothersubpath -&gt; some-service/subpath/anothersubpath
  </code></pre>
  
  <p>However, when I sysdig the traffic coming into <code>some-service</code>, I see that Istio has rewritten the path to:</p>
  
  <pre><code>GET //subpath/anothersubpath HTTP/1.1
  </code></pre>
  
  <p>Notice the two slashes in the GET request. In the VirtualService spec <code>rewrite.uri</code> field, I can't seem to leave that field empty or add an empty string there. Doing so causes the resource not to validate.</p>
  
  <p>I.e. I can NOT do this:</p>
  
  <pre><code>    rewrite:
        uri: ""
  </code></pre>
  
  <p>And can NOT do this</p>
  
  <pre><code>    rewrite:
        uri:
  </code></pre>
  
  <p>How can I define a VirtualService rewrite to send traffic to the root of the destination service? Any help is much appreciated. </p>