I'm trying to perform a 301 redirect for some requests using Istio's Gateway with VirtualService. I've done everything, and it works perfectly if the request is over HTTP, but it doesn't work for HTTPS.
The scenario is as follows: I have an address https://www.myhost.com/oldpath, and I want to redirect it to https://myhost.com/newpath. I have several URLs that need this change to the host without "www." and also change the path.
Please note that in my Gateway, I'm using ManagedCertificate, which generated the certificate within the Google Cloud Platform. Since I can't create a secret to pass the tls attribute of the Gateway, I configured it as PASSTHROUGH.
When my certificate didn't have the domain with "www.," it worked. However, when I created the ManagedCertificate including both domains with and without "www.," the redirection stopped working. Below are my files.
#managed-certificate-file
apiVersion: networking.gke.io/v1
kind: ManagedCertificate
metadata:
name: managed-cert
spec:
domains:
- myhost.com
- www.myhost.com
---
#ingress-file
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
kubernetes.io/ingress.global-static-ip-name: my-external-ip-gcp
kubernetes.io/ingress.class: "gce"
kubernetes.io/ingress.allow-http: "true"
networking.gke.io/v1beta1.FrontendConfig: my-frontend-config
spec:
defaultBackend:
service:
name: my-important-service
port:
name: http
---
#frontend-config-file
apiVersion: networking.gke.io/v1beta1
kind: FrontendConfig
metadata:
name: my-frontend-config
spec:
sslPolicy: my-ssl-policy
redirectToHttps:
enabled: false
---
#gateway-file
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: my-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
- port:
number: 443
name: https
protocol: HTTPS
hosts:
- "*"
tls:
mode: PASSTHROUGH
---
#virtual-service file
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: myhost-redirect
spec:
hosts:
- "www.myhost.com"
gateways:
- my-gateway
http:
- match:
- uri:
exact: /register
redirect:
uri: /sign-up
authority: myhost.com
scheme: "https"
- match:
- uri:
exact: /get-my-password
redirect:
uri: /password-reset
authority: myhost.com
scheme: "https"