<p>I'm using <code>nginx.ingress.kubernetes.io/permanent-redirect: https://www.google.com</code> but want to pass down parameters after / in the redirect. But can't get it to work with pure ingress-nginx, would be sweet if you could set /$1 or something similar. Is this possible with a mix of other annotations or tricks?</p>

<p>For example
<a href="https://www.example.com/hello" rel="noreferrer">https://www.example.com/hello</a></p>

<p>Should redirect to
<a href="https://www.google.com/hello" rel="noreferrer">https://www.google.com/hello</a></p>

CodingNoob123
<p>It's surprisingly easy:</p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/permanent-redirect: http://www.google.com$request_uri
spec:
  rules:
  - host: www.example.com
    http:
      paths:
      - path: /testpath
        pathType: Prefix
        backend:
          serviceName: test
          servicePort: 80
</code></pre>

<p>It leads to something like this in <code>nginx.conf</code>:</p>

<pre><code>if ($uri ~* /) {
        return 301 http://www.google.com$request_uri;
}
</code></pre>

<p>It seems you can use any <a href="https://nginx.org/en/docs/varindex.html" rel="noreferrer">nginx variable</a> in the address. So I guess you could do things like <code>$scheme://www.google.com$request_uri</code> as well :)</p>

<p>I first tried a <code>nginx.ingress.kubernetes.io/server-snippet</code> block like suggested in another answer here, but <code>redirect 301 http://www.google.com$request_uri;</code> hijacked too much in <code>nginx.conf</code> and stopped <a href="https://cert-manager.io/" rel="noreferrer">cert-manager</a> from working. So I needed a better integrated solution.</p>

<p>If you want to debug, you can just look at <code>nginx.conf</code> yourself, it's really easy:</p>

<pre><code>$ kubectl exec -n nginx-ingress nginx-ingress-controller-*** -- cat /etc/nginx/nginx.conf
</code></pre>
