<p>I am trying to use kubernetes nginx ingress controller: (quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.22.0). Below is my ingress object.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 name: cc-store-ingress
 annotations:
  kubernetes.io/ingress.class: "nginx"
  nginx.ingress.kubernetes.io/rewrite-target: /$1
  nginx.ingress.kubernetes.io/add-base-url: "true"
  #nginx.ingress.kubernetes.io/configuration-snippet: |
  # sub_filter "http://my-ip:30021/" "http://my-ip:30021/app/";
  # sub_filter_once off;
spec:
 #tls:
 #- secretName: tls-secret
 rules:
 - host: my-ip
  http:
   paths:
   - path: /app/?(.*)
    backend:
     serviceName: appsvc
     servicePort: 7201
</code></pre>

<p>When I try to access the this service via ingress I hit a blank page, which I understand is because response (set of few java scripts , css and others) are returning to my-ip:30021/ instead of my-ip:30021/app. (checked the nginx logs initial connection gives 200 response subsequent loading of css and js are failing with 404)</p>

<p>Is there a way to overcome this? Neither "sub_filter" nor add-base-url annotations helped.</p>

<p>Is there any way to achieve the path rewriting for response. Would using any other ingress controller (instead of nginx) can make this easier to overcome ?</p>

<p>This is a sample of how I did adding base path to a service which completely doesn't support it. As well a solution for handling redirects to the urls without base path.</p>

<pre><code>annotations:
  kubernetes.io/ingress.class: nginx
  # catch $1 from 'path' capture group
  nginx.ingress.kubernetes.io/rewrite-target: /$1
  # handle redirects
  # nginx.ingress.kubernetes.io/proxy-redirect-from: http://&lt;host&gt;/
  # nginx.ingress.kubernetes.io/proxy-redirect-to: /&lt;basePath&gt;/
  nginx.ingress.kubernetes.io/configuration-snippet:
    proxy_set_header Accept-Encoding "";
    sub_filter_last_modified off;

    # add base path to all static resources
    sub_filter '&lt;head&gt;' '&lt;head&gt; &lt;base href="/&lt;basePath&gt;/"&gt;';
    sub_filter 'href="/' 'href="';
    sub_filter 'src="/' 'src="';

    # set types of files to 'sub-filter'
    sub_filter_once off;
    sub_filter_types text/html text/css text/javascript application/javascript;
...
    - path: /&lt;basePath&gt;/?(.*)
</code></pre>
