Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes Ingress Redirect and Rewrite

quick question as I am sure its an easy fix, just cannot seem to figure it out!

We have a site that runs on www.awesomeapp.com - all working perfectly on ingress routing

However I want to also redirect the route domain to www.awesomeapp.com for example awesomeapp.com => www.awesomeapp.com

I added this annotation nginx.ingress.kubernetes.io/permanent-redirect: https://www.awesomeapp.com

Again all working perfectly.

My question is how do I also get the path added as well. For example

user enters in awesomeapp.com/myawesomepage and what I want is it to not only redirect but append the path as well so it ends up like this

www.blahblah.com/myawesomepage

I added this ingress.kubernetes.io/rewrite-target: /$1$2 but this does not work, and that is in conjunction with this - path: /(/|$)(.*)

Full yaml config as follows:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:  
    name: root-routing
    labels:
      app: awesomeapp
    annotations:
        kubernetes.io/ingress.class: nginx     
        nginx.ingress.kubernetes.io/permanent-redirect: https://www.awesomeapp.com
        ingress.kubernetes.io/rewrite-target: /$1$2
spec:
    tls:
    - hosts:
        - awesomeapp.com
      secretName: awesomeapp-com-tlscert
    rules:
    - host: awesomeapp.com
      http:
        paths:
        - path: /(/|$)(.*)
          pathType: Prefix
          backend:
            service:
                name: awesomeapp
                port:
                    number: 80

Thanks John

like image 979
John Hyde Avatar asked Feb 02 '26 02:02

John Hyde


1 Answers

nginx.ingress.kubernetes.io/server-snippet: | return 301 https://www.awesomeapp.com$request_uri;

like image 180
John Hyde Avatar answered Feb 04 '26 01:02

John Hyde



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!