# Rewrite targets in Kong ingress

**URL:** <https://discuss.konghq.com/t/rewrite-targets-in-kong-ingress/7758>\
**Category:** Questions\
**Tags:** kubernetes\
**Created:** [January 18, 2021, 10:58am UTC](https://discuss.konghq.com/t/rewrite-targets-in-kong-ingress/7758 "2021-01-18T10:58:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arjunkrisha](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/arjunkrisha/32/2498_2.png) [@Arjunkrisha](https://discuss.konghq.com/u/Arjunkrisha)\
**Post date:** [January 18, 2021, 10:58am UTC](https://discuss.konghq.com/t/rewrite-targets-in-kong-ingress/7758/1 "2021-01-18T10:58:50Z")

</div>

Hi,

I installed kong kubernetes ingress controller. I created an ingress resource for my application.

> ```
> apiVersion: networking.k8s.io/v1beta1
> kind: Ingress
> metadata:
> name: baster-api-ingress
> namespace: baster
> annotations:
> nginx.ingress.kubernetes.io/rewrite-target: /$1
> kubernetes.io/ingress.class: kong
> spec:
> rules:
> - http:
> paths:
> - path: /(.*)
> backend:
> serviceName: baster-api
> servicePort: 5000
> 
> ```

> ```
> apiVersion: networking.k8s.io/v1beta1
> kind: Ingress
> metadata:
> name: mongo-express-ingress
> namespace: baster
> annotations:
> kubernetes.io/ingress.class: kong
> spec:
> rules:
> - http:
> paths:
> - path: /mongo-express
> backend:
> serviceName: mongo-express
> servicePort: 8081
> 
> ```

Before using Kong i was using nginx ingress as k8s ingress controller and used it for sending the URI paths to the upstream using rewrite-target plugin ([Rewrite - Ingress-Nginx Controller](https://kubernetes.github.io/ingress-nginx/examples/rewrite/)).

When i access [http://hostname/path1](http://hostname/path1), [http://hostname/path2](http://hostname/path2) then it sends to _baster-api_ service with uri path _/path1_ and _/path2_ respectively…

But, If i send [http://hostname/mongo-express](http://hostname/mongo-express) it sends to _mongo-express_ service with _/mongo-express_ uri to this upstream

It was working fine and was routing the ingress to right service based on the uri and sends the uri to the target services.

Now i started using Kong and used the same nginx rewrite plugin to send the uri to right upstream. But now it is always sending to baster-api even if i try to access with /mongo-express.

How to fix this ? is there any native way in kong to send the URI paths to the upstream services based on match ? or can i make the nginx annotation work in someway ?

---

<div class="post-metadata">

**Author:** ![Arjunkrisha](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/arjunkrisha/32/2498_2.png) [@Arjunkrisha](https://discuss.konghq.com/u/Arjunkrisha)\
**Post date:** [January 25, 2021, 10:32am UTC](https://discuss.konghq.com/t/rewrite-targets-in-kong-ingress/7758/2 "2021-01-25T10:32:24Z")

</div>

I fixed it and made it work. But had to make some changes to the regex for forwarding and removed the nginx rewrite.

> apiVersion: [networking.k8s.io/v1](http://networking.k8s.io/v1)  
> kind: Ingress  
> metadata:  
> name: mongo-express-ingress  
> namespace: {{ .Values.namespace }}  
> annotations:  
> [kubernetes.io/ingress.class:](http://kubernetes.io/ingress.class:) kong  
> spec:  
> rules:
> 
> - http:  
> paths:
> - path: /mongo-express(.\*)  
> pathType: Prefix  
> backend:  
> service:  
> name: {{ .Values.mongo\_express.service\_name }}  
> port:  
> number: 8081
> 
> > ```
> > root@kong-microk8s-001:/opt/baster# cat helm/templates/baster-api-ingress.yaml
> > apiVersion: networking.k8s.io/v1
> > kind: Ingress
> > metadata:
> > name: baster-api-ingress
> > namespace: {{ .Values.namespace }}
> > annotations:
> > nginx.ingress.kubernetes.io/rewrite-target: /$1
> > kubernetes.io/ingress.class: kong
> > spec:
> > rules:
> > - http:
> > paths:
> > - path: /(.*)
> > pathType: ImplementationSpecific
> > backend:
> > service:
> > name: {{ .Values.baster_api.service_name }}
> > port:
> > number: 5000
> > 
> > ```

---

<div class="post-metadata">

**Author:** ![mmfalcao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/mmfalcao/32/3534_2.png) [@mmfalcao](https://discuss.konghq.com/u/mmfalcao)\
**Post date:** [September 23, 2022, 1:15pm UTC](https://discuss.konghq.com/t/rewrite-targets-in-kong-ingress/7758/3 "2022-09-23T13:15:56Z")

</div>

I think you should use the annotation for [strip-path](https://docs.konghq.com/kubernetes-ingress-controller/latest/references/annotations/#konghqcomstrip-path)

[konghq.com/strip-path:](http://konghq.com/strip-path:) “true”
