Answers: <p>To get rid of <code>index.html</code> at the end of your URL using Istio Virtual Service, you can use the <code>rewrite</code> field with a regular expression. Here's a config that should do the trick:</p>
  <pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.istio.io/v1alpha3
  kind: VirtualService
  metadata:
    name: allure-virtual-service
  spec:
    hosts:
    - &quot;*&quot;
    gateways:
    - your-gateway-name
    http:
    - match:
      - uri:
          regex: ^(.*/)index.html$
      rewrite:
        uri: &quot;$1&quot;
      route:
      - destination:
          host: allure-service-clusterip.allure-docker-service.svc.cluster.local
          port:
            number: 7070
  </code></pre>
  <p>Here's what's going on:</p>
  <ol>
  <li><p>The ﻿match section uses a regular expression ﻿^(.<em>/)index.html$ to
  match URLs that end with ﻿/index.html. The ﻿(.</em>) captures the path
  before ﻿/index.html.</p>
  </li>
  <li><p>The ﻿rewrite section rewrites the URI using the
  captured group from the match. The ﻿uri field is set to ﻿&quot;$1&quot;, which
  replaces the matched URI with the captured path, effectively
  removing ﻿/index.html from the end.</p>
  </li>
  <li><p>The ﻿route section specifies
  where the request should be sent, which is the
  ﻿allure-service-clusterip service in the ﻿allure-docker-service
  namespace.</p>
  </li>
  </ol>
  <p>Don't forget to replace ﻿your-gateway-name with the actual name of your Istio Gateway.
  With this setup, requests to ﻿https://somehost/somepath/index.html will be rewritten to ﻿https://somehost/somepath and sent to the specified destination service.</p>
  
Answers: CC BY-SA 4.0
Answers: 2024-04-26T12:25:31.260Z
Answers: Thank you for the answer. But I tried this way and got 400 Bad Request.   
  
  curl shows:  
  `
  > HEAD /allure-ui/allure-docker-service-ui/projects/exp-test-automation-service/reports/latest/index.html HTTP/2
  > Host: ***
  > accept: */*
  
  * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
  * old SSL session ID is stale, removing
  * Connection state changed (MAX_CONCURRENT_STREAMS == 2147483647)!
  
  HTTP/2 400
  content-length: 11
  content-type: text/plain
  server: istio-envoy
  `
    
  Logs of istio-proxy container of the pod:  
  "- - HTTP/1.1" 400 DPE http1.codec_error - ...
Answers: n_alexeyev
Answers: CC BY-SA 4.0
Answers: 2024-04-26T17:19:49.570Z
Answers: Thanks for the feedback, I was working off my notes as I went through the same issue a while back. Looks like the API might have changed in newer versions. I will double check and update my answer.
Answers: Thomas Vincent
Answers: CC BY-SA 4.0
Answers: 2024-04-26T11:00:58.907Z
Answers: 2024-04-26T11:00:58.907Z
Answers: Thomas Vincent
Body: <p>I need to get rid of index.html at the end of url, so<br />
  https://somehost/somepath/index.html<br />
  is rewritten to<br />
  https://somehost/somepath</p>
  <p>I tried</p>
  <pre class="lang-yaml prettyprint-override"><code>  - match:
      - uri:
          regex: (.*)\/index.html
      route:
      - destination:
          host: allure-service-clusterip.allure-docker-service.svc.cluster.local
          port:
            number: 7070
      rewrite:
        uriRegexRewrite:
          match: (.*)\/index.html
          rewrite: /\1
  </code></pre>
  <p>and</p>
  <pre class="lang-yaml prettyprint-override"><code>- match:
    - uri:
        prefix: /index.html
    route:
    - destination:
        host: allure-service-clusterip.allure-docker-service.svc.cluster.local
        port:
          number: 7070
    rewrite:
        uri: /
  </code></pre>
  <p>but it does not work.</p>
  <p>Originally it was implemented with nginx ingress as following:<br />
  <a href="https://github.com/fescobar/allure-docker-service-examples/blob/master/allure-docker-kubernetes-example/allure-ingress-service-load-balancer.yml" rel="nofollow noreferrer">https://github.com/fescobar/allure-docker-service-examples/blob/master/allure-docker-kubernetes-example/allure-ingress-service-load-balancer.yml</a></p>
  <p>Any ideas?</p>
  
Tags: <istio><url-rewrite>
Title: How to rewrite the last prefix (/index.html) at the end of url in Istio VirtualService?
UserDisplayName: n_alexeyev
ThreadText: # How to rewrite the last prefix (/index.html) at the end of url in Istio VirtualService?
  
  (Asked by: username_0 on 2024-04-26)
  
  I need to get rid of index.html at the end of url, so  
  https://somehost/somepath/index.html  
  is rewritten to  
  https://somehost/somepath
  
  I tried
  
  ```yaml
    - match:
      - uri:
          regex: (.*)\/index.html
      route:
      - destination:
          host: allure-service-clusterip.allure-docker-service.svc.cluster.local
          port:
            number: 7070
      rewrite:
        uriRegexRewrite:
          match: (.*)\/index.html
          rewrite: /\1
  
  ```
  
  and
  
  ```yaml
  - match:
    - uri:
        prefix: /index.html
    route:
    - destination:
        host: allure-service-clusterip.allure-docker-service.svc.cluster.local
        port:
          number: 7070
    rewrite:
        uri: /
  
  ```
  
  but it does not work.
  
  Originally it was implemented with nginx ingress as following:  
  <https://github.com/fescobar/allure-docker-service-examples/blob/master/allure-docker-kubernetes-example/allure-ingress-service-load-balancer.yml>
  
  Any ideas?
  
  **Tags:** istio, url-rewrite
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-04-26. Score: 0
  
  To get rid of `index.html` at the end of your URL using Istio Virtual Service, you can use the `rewrite` field with a regular expression. Here's a config that should do the trick:
  
  ```yaml
  apiVersion: networking.istio.io/v1alpha3
  kind: VirtualService
  metadata:
    name: allure-virtual-service
  spec:
    hosts:
    - "*"
    gateways:
    - your-gateway-name
    http:
    - match:
      - uri:
          regex: ^(.*/)index.html$
      rewrite:
        uri: "$1"
      route:
      - destination:
          host: allure-service-clusterip.allure-docker-service.svc.cluster.local
          port:
            number: 7070
  
  ```
  
  Here's what's going on:
  
  1. The ﻿match section uses a regular expression ﻿^(.*/)index.html$ to
     match URLs that end with ﻿/index.html. The ﻿(.*) captures the path
     before ﻿/index.html.
  2. The ﻿rewrite section rewrites the URI using the
     captured group from the match. The ﻿uri field is set to ﻿"$1", which
     replaces the matched URI with the captured path, effectively
     removing ﻿/index.html from the end.
  3. The ﻿route section specifies
     where the request should be sent, which is the
     ﻿allure-service-clusterip service in the ﻿allure-docker-service
     namespace.
  
  Don't forget to replace ﻿your-gateway-name with the actual name of your Istio Gateway.
  With this setup, requests to ﻿https://somehost/somepath/index.html will be rewritten to ﻿https://somehost/somepath and sent to the specified destination service.
  
  > **Comments:**
  > **username_0**: Thank you for the answer. But I tried this way and got 400 Bad Request.     curl shows:   ` > HEAD /allure-ui/allure-docker-service-ui/projects/exp-test-automation-service/reports/latest/index.html HTTP/2 > Host: *** > accept: */*  * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4): * old SSL session ID is stale, removing * Connection state changed (MAX_CONCURRENT_STREAMS == 2147483647)!  HTTP/2 400 content-length: 11 content-type: text/plain server: istio-envoy `    Logs of istio-proxy container of the pod:   "- - HTTP/1.1" 400 DPE http1.codec_error - ...  
  > **username_1**: Thanks for the feedback, I was working off my notes as I went through the same issue a while back. Looks like the API might have changed in newer versions. I will double check and update my answer.  
  
  ---
  
  