<p>I have setup nginx ingress like this on kubernetes</p>

<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: animefanz-ktor-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  tls:
    - hosts:
        - mydomain.com
      secretName: my-tls
  rules:
    - host: mydomain.com
      http:
        paths:
          - path: /myapp(/|$)(.*)
            backend:
              serviceName: myservice
              servicePort: 8080
</code></pre>

<p>So everything working fine but i want to do one thing when ever <a href="https://mydomian.com/myapp/api/history" rel="nofollow noreferrer">https://mydomian.com/myapp/api/history</a> called then i want to redirect it to <a href="https://mydomain2.com/myapp2/api/history" rel="nofollow noreferrer">https://mydomain2.com/myapp2/api/history</a> along with get params that is.</p>

<p>So i want to just forward one api request to another server.</p>

William
<p>I think you can configure it with nginx <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#server-snippet" rel="nofollow noreferrer">server-snippet</a>/<a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#configuration-snippet" rel="nofollow noreferrer">configuration-snippet</a> annotation.</p>

<hr>

<p>There is related <a href="https://stackoverflow.com/questions/58687909/kubernetes-ingress-domain-redirect">stackoverflow question</a> about that.</p>

<p>And examples provided by @Thanh Nguyen Van</p>

<pre><code>metadata:
      annotations:
        nginx.ingress.kubernetes.io/configuration-snippet: |
         rewrite /preview https://test.app.example.com$uri permanent;

spec:
      rules:
      - host: test.example.io
        http:
          paths:
          - path: /
            backend:
              serviceName: service-1
              servicePort: 80
      - host: test.app.example.io
        http:
          paths:
          - path: /preview/*
            backend:
              serviceName: service-2
              servicePort: 80
</code></pre>

<p>And @Harsh Manvar</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/server-snippet: |
          location ~ /preview {
             rewrite /preview https://test.app.example.com$uri permanent;
          }
  name: staging-ingress
spec:
  rules:
  - host: test.example.io
    http:
      paths:
      - path: /
        backend:
          serviceName: service-1
          servicePort: 80
      - path: /preview/*
        backend:
          url: 
          serviceName: service-2
          servicePort: 80
  tls:
  - hosts:
    - test.example.io
    secretName: staging  
</code></pre>

<hr>

<p>Additionally there is related <a href="https://github.com/kubernetes/ingress-nginx/issues/605" rel="nofollow noreferrer">github issue</a> about that.</p>

<p>Hope you find this useful.</p>
