<p>How do I redirect all my <code>hrefs</code> within my response to hit my new path. For e.g., my ingress file is</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-odin
  annotations:    
    nginx.ingress.kubernetes.io/rewrite-target: /$1

spec:
  rules:
  - http:
      paths:
      - path: /odin/?(.*)
        backend:
          serviceName: flask-app-tutorial
          servicePort: 8080
</code></pre>

<p>When I visit the page at <a href="https://mysite/odin" rel="nofollow noreferrer">https://mysite/odin</a>. It works and returns back the response:</p>

<p>The HTML response is:</p>

<pre><code>&lt;html&gt;
..
    &lt;body&gt;
        &lt;div&gt;
            &lt;a href="/v0/index"&gt;Home&lt;/a&gt;
            &lt;a href="/v0/login"&gt;Login&lt;/a&gt;
        &lt;/div&gt;

    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>However, as you can see, the relative links are like <code>&lt;a href="/v0/index"&gt;Home&lt;/a&gt;</code>. If I click on that, it won't work since there is no link like <code>http://mysite/v0/index</code>. If I click on the link, I want it to go to <code>http://mysite/odin/v0/index</code>. Is it possible either by modifying the links in the response to have <code>odin</code> or if I do click on it, it looks at the source url i.e. <code>http://mysite/odin</code> and direct it relative to that?</p>

<pre><code>Nginx Version: 1.15.10
ingress-nginx: 0.24.0
</code></pre>

<p>So far,I have tried the following.</p>

<pre><code>nginx.ingress.kubernetes.io/configuration-snippet: |
  proxy_set_header Accept-Encoding ""; #disable compression
  sub_filter '&lt;head&gt;' '&lt;head&gt; &lt;base href="/odin/"&gt;';


nginx.ingress.kubernetes.io/add-base-url: ":true"
nginx.ingress.kubernetes.io/app-root: /odin

nginx.ingress.kubernetes.io/use-regex: "true"
</code></pre>

<p>I have also tried <a href="https://github.com/kubernetes/ingress-nginx/pull/3174#issuecomment-483315744" rel="nofollow noreferrer">this</a> i.e.</p>

<pre><code> change the spec.rules.host.paths.path from /odin/?(.*) to/(odin/.*)
</code></pre>

<p>There may be a typo in the advice above. I think it should <code>http</code> instead of <code>host</code>.</p>

RAbraham
<p>I had a similar problem and inspired by your question I found a solution which worked for me.
Your annotation should work like this:</p>

<pre><code>nginx.ingress.kubernetes.io/configuration-snippet: |
  sub_filter_once on;
  sub_filter '&lt;base href="/"' '&lt;base href="/odin/"';
</code></pre>

<p>As you see sub_filter is now enabled and I used <em>base</em> instead of <em>head</em>.</p>
