0

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

  - 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

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

1 Answer 1

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:

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.

2
  • 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 - ...
    – n_alexeyev
    Commented Apr 26 at 12:25
  • 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. Commented Apr 26 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.