<p>recently I have deployed an kubernetes cluster which is running wordpress instance and phpmyadmin. I'm using Nginx ingress controller to perform path based routing for both the services. However, request to <code>/</code> is happening without any hassle but when I request <code>domain.com/phpmyadmin/</code> I get a login page after which I have been redirected to <code>domain.com/index.php</code> instead of <code>domain.com/phpmyadmin/index.php</code>. Please suggest me possible turn around for this. Thank you guys for the support :)</p>
<p>My ingress.yaml</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress-nginx
  annotations: 
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: &quot;false&quot;
    nginx.ingress.kubernetes.io/add-base-url : &quot;true&quot;
    nginx.ingress.kubernetes.io/rewrite-target: &quot;/$2&quot;
    # ingress.kubernetes.io/rewrite-target: &quot;^/phpmyadmin/&quot;
spec:
  rules:
    - host: example.domain.com
      http:
        paths:
          - path: /
            backend:
              serviceName: wordpress
              servicePort: 80
          - path: /phpmyadmin(/|$)(.*)
            backend:
              serviceName: phpmyadmin
              servicePort: 80
  
</code></pre>

Devopsception
<p>I'd say issue is not on <a href="https://kubernetes.github.io/ingress-nginx/" rel="nofollow noreferrer">Nginx Ingress</a> side.</p>
<pre><code>nginx.ingress.kubernetes.io/rewrite-target: &quot;/$2&quot;
...
- path: /phpmyadmin(/|$)(.*)
</code></pre>
<p>Should work properly for you.</p>
<p>However there is second part, configuration of <code>myphpadmin</code>. As you didn't provide this configuration I would guess what could cause this issue.</p>
<p>Like mentioned in <a href="https://docs.phpmyadmin.net/en/latest/config.html#config" rel="nofollow noreferrer">phpmyadmin docs</a>, sometimes you need to set <code>$cfg['PmaAbsoluteUri']</code></p>
<blockquote>
<p>In some setups (like separate SSL proxy or load balancer) you might have to set $cfg['PmaAbsoluteUri'] for correct redirection.</p>
</blockquote>
<p>As I based on <a href="https://gist.github.com/dnaroma/178b3b187aa329c01b27d90a7b38709c" rel="nofollow noreferrer">this configuration</a>, many depends on how you configured <code>PMA_ABSOLUTE_URI</code>, is it <code>http://somedomain.com/phpmyadmin</code> or different?
Is important as you might encounter situation like:</p>
<ul>
<li>When you enter to <code>http://somedomain.com/phpmyadmin</code> and login you will be redirected to <code>http://somedomain.com/</code> so <code>Ingress</code> will redirect you to <code>path: /</code> set in ingress</li>
<li>If you will again enter <code>http://somedomain.com/phpmyadmin</code> you will be able to see <code>phpmyadmin</code> content, like you would be already logged in.</li>
</ul>
<p>You could try to add <code>env</code> in your <code>myphpadmin</code> deployment. It would look similar like below:</p>
<pre><code>  env:
    - name: PMA_ABSOLUTE_URI
      value: http://somedomain.com/myphpadmin/
</code></pre>
<p>Last thing, its not recommended to use expose <code>phpmyadmin</code> without <code>https</code>.</p>
<p>For some extra information you can read <a href="https://blog.dnaroma.eu/2020/07/31/study-k8s-with-microk8s/" rel="nofollow noreferrer">this</a> article.</p>
<p><strong>In short:</strong></p>
<ul>
<li>Nginx ingress configuration looks ok</li>
<li>Check your <code>myphpadmin</code> configuration, especially <code>PMA_ABSOLUTE_URI</code>.</li>
</ul>
