<p>I have a cluster with Nginx ingress. I receive an API request, for example:</p>
<pre><code>/api/v1/user?json={query}
</code></pre>
<p>I want to redirect this request with ingress to my service. I want to modify it like this:</p>
<pre><code>/api/v2/user/{query}
</code></pre>

Ruben Aleksanyan
<p>Assuming your domain name is <code>example.com,</code> and you have a service called <code>example-service</code> exposing port <code>80</code>, you can achieve this task by defining the following ingress rule.</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/configuration-snippet: |
       if ($arg_json) {
           return 302 https://example.com/api/v2/user/$arg_json;
       }
    nginx.ingress.kubernetes.io/use-regex: 'true'
  name: ingress-rule
  namespace: default
spec:
  rules:
  - host: example.com
    http:
      paths:
      - backend:
          service:
            name: example-service
            port:
              number: 80
        path: /api/v1/user(.*)
        pathType: Prefix

</code></pre>
