I’ve a react app hosted with istio. In this case if user refresh any page other then the index.html he gets a 404 as route to that path does not exist with istio. Is there a way to redirect traffic to ui pod for any 404?
What I want is if no route match redirect it to ui pod. instead of throwing a 404.
I don’t think it is possible to redirect on 404. However, if you wish to route everything that is not index.html to index.html you can do something like this:
cat <<EOF | kubectl apply -f -
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bookinfo
spec:
hosts:
- "*"
gateways:
- bookinfo-gateway
http:
- match:
- uri:
exact: /index.html
route:
- destination:
host: productpage
port:
number: 9080
- match:
- uri:
prefix: /
redirect:
uri: /index.html
EOF
This example is for book info but you should get the idea. Modify the VirtualService for your Gateway to have a second case that doesn’t match your public page. Have that case take everything (“prefix /”), and redirect to index.html.
Thanks @ed.snible.
In my case I’ve couple of routes defined by virtualservice.
for example, I’ve route for anything coming on port 80 with prefix /api, send it to api service on port 8080.
So, here I want if it’s not exact: /index.html
or prefix: /api
then reroute: /index.html
The match
es in the virtual service are processed in order. The last one can be a “catch all” for anything not covered by the others.
In my case, there are multiple virtualservices(files) for a host based on path. In this case the order is not guaranteed. but this helps I can have a single virtualservice with multiple matches and “catch all” in the last.
Thanks