<p>I have a service which is running in kubernetes, and has a path prefix <code>/api</code>. Now I want to use Ingress to access it through the host address <code>example.com/service1/</code> because I have multiple services. But the problem is that ingress redirects all the requests from path <code>service1/</code> with that prefix <code>service1/</code>, but I want it to redirect from <code>example.com/service1/</code> to my service with just <code>/</code> (so if I request <code>example.com/service1/api</code> it will redirect to service with just <code>/api</code>). Can I achieve something like this? I'm writing Ingress configuration in the helm chart of the service.
Ingress configuration in service chart file <code>values.yaml</code> looks like this:</p>
<pre><code>...
ingress:
  enabled: true
  className: &quot;&quot;
  annotations: {}
  # kubernetes.io/ingress.class: nginx // this comment was created when generating helm chart
  hosts:
    - host: example.com
      paths:
        - path: /service1(/|$)(.*)
          pathType: ImplementationSpecific
          backend:
            serviceName: $name
            servicePort: http
  tls: []
  ...
</code></pre>
<p>And <code>ingress.yaml</code> inside <code>templates/</code> folder is a default file that was generated by <code>helm</code> when I was creating a chart for the service. It just uses values from <code>values.yaml</code> to configure ingress. I didn't find anything, only <a href="https://stackoverflow.com/questions/63532836/kubernetes-ingress-not-redirecting-to-correct-path">this question</a> which is basically saying that I need to add either prefix <code>service1/</code> to my service or just use <code>/api</code> in the Ingress configuration. But is there solution suitable for my needs?</p>

Arzybek
<p><em>This is a community wiki answer posted for better visibility. Feel free to expand it.</em></p>
<p>Based on the solution provided in the comments (method 1 example 2 in the Medium <a href="https://medium.com/ww-engineering/kubernetes-nginx-ingress-traffic-redirect-using-annotations-demystified-b7de846fb43d" rel="nofollow noreferrer">post</a> ), a possible <code>values.yaml</code> file for Ingress might looks like below.</p>
<pre><code>...
ingress:
  enabled: true
  className: &quot;&quot;
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: http://example.com/$2 
  hosts:
    - host: example.com
      paths:
        - path: /service1(/|$)(.*)
          backend:
            serviceName: $name
            servicePort: http
  tls: []
  ...
</code></pre>
