<p>I want to use Kong’s Capturing Group in Ingress k8s object to perform an uri rewriting.
I want to implement the following logic:
https://kong_host:30000/service/audits/health -&gt; (rewrite) https://kong_host:30000/service/audit/v1/health</p>
<p>Ingress resource:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: audits
  annotations:
    konghq.com/plugins: audits-rewrite
spec:
  rules:
  - http:
      paths:
      - path: /service/audits/(?&lt;path&gt;\\\S+)
        backend:
          serviceName: audits
          servicePort: 8080
</code></pre>
<p>KongPlugin</p>
<pre><code>apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: audits-rewrite
config: 
  replace:
    uri: /service/audit/v1/$(uri_captures[&quot;path&quot;])
plugin: request-transformer
</code></pre>
<p>Thanks.</p>

mohamed.Yassine.SOUBKI
<p>As pointed in documentation you are not able to use <code>v1beat1</code> ingress API version to capture groups in paths.</p>
<p><a href="https://docs.konghq.com/hub/kong-inc/request-transformer/#examples" rel="nofollow noreferrer">https://docs.konghq.com/hub/kong-inc/request-transformer/#examples</a></p>
<p>You need to upgrade you <code>k8s</code> cluster to <code>1.19</code> or higher version to use this feature.</p>
<p>I also had similar problem and resolved it will following configuration:</p>
<p>Ingress resource:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: audits
  annotations:
    konghq.com/plugins: audits-rewrite
spec:
  rules:
  - http:
      paths:
      - path: /service/audits/(.*)
        backend:
          serviceName: audits
          servicePort: 8080
</code></pre>
<p>KongPlugin</p>
<pre><code>apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: audits-rewrite
config: 
  replace:
    uri: /service/audit/v1/$(uri_captures[1])
plugin: request-transformer
</code></pre>
