# Strip part of URI

**URL:** <https://discuss.konghq.com/t/strip-part-of-uri/2738>\
**Category:** Feature Requests & Feedback\
**Created:** [February 1, 2019, 4:17pm UTC](https://discuss.konghq.com/t/strip-part-of-uri/2738 "2019-02-01T16:17:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![pajel](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pajel](https://discuss.konghq.com/u/pajel)\
**Post date:** [February 1, 2019, 4:17pm UTC](https://discuss.konghq.com/t/strip-part-of-uri/2738/1 "2019-02-01T16:17:45Z")

</div>

In addition to the strip\_path=true/false option we need to strip only a part (prefix) of the path.  
I’d suggest an option like strip\_path\_prefix="/some-text".  
The use case is having a single service with multiple routes attached which allow different consumers, for example:

- /route - strip\_path=true, allow consumer1
- /route/health - strip\_path\_prefix="/route", allow consumer2

Such rewrites are basic Nginx functionality so it shouldn’t be hard to implement.  
I have seen quite a few people asking for this feature, eg:  
[https://discuss.konghq.com/t/service-with-two-strip-path-routes/2596](https://discuss.konghq.com/t/service-with-two-strip-path-routes/2596)  
[https://discuss.konghq.com/t/strip-part-of-a-path-prefix-when-routing/1940](https://discuss.konghq.com/t/strip-part-of-a-path-prefix-when-routing/1940)  
[https://discuss.konghq.com/t/strip-some-part-of-uri/735](https://discuss.konghq.com/t/strip-some-part-of-uri/735)

Appreciate any reaction,  
thanks Pavel

---

<div class="post-metadata">

**Author:** ![gleg](https://avatars.discourse-cdn.com/v4/letter/g/7cd45c/32.png) [@gleg](https://discuss.konghq.com/u/gleg)\
**Post date:** [February 1, 2019, 4:30pm UTC](https://discuss.konghq.com/t/strip-part-of-uri/2738/2 "2019-02-01T16:30:12Z")

</div>

This would be really useful for us as well

---

<div class="post-metadata">

**Author:** ![jacob-bennett](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@jacob-bennett](https://discuss.konghq.com/u/jacob-bennett)\
**Post date:** [February 1, 2019, 4:45pm UTC](https://discuss.konghq.com/t/strip-part-of-uri/2738/3 "2019-02-01T16:45:45Z")

</div>

+1 Agreed would find this helpful also

---

<div class="post-metadata">

**Author:** ![Abhishek\_Udaya\_Chand](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@Abhishek\_Udaya\_Chand](https://discuss.konghq.com/u/Abhishek_Udaya_Chand)\
**Post date:** [March 12, 2019, 7:24am UTC](https://discuss.konghq.com/t/strip-part-of-uri/2738/4 "2019-03-12T07:24:37Z")

</div>

yes please i am looking for same functionality

> [@Is there a way we can have different upstream url than what the client calls](https://discuss.konghq.com/t/is-there-a-way-we-can-have-different-upstream-url-than-what-the-client-calls/2988):
>
> Hello guys, i am using kong 1.0.3 i have same micro-service deployed in two countries. lets say country A and country B. They both will have same endpoints. i want to achieve the following in KONG. client calls kong with /A/api =\> kong =\> service-A/api /B/api =\> kong =\> service-B/api i want to have two services in kong here the api path is same for different services. service-A and service-B.

---

<div class="post-metadata">

**Author:** ![Kunone](https://avatars.discourse-cdn.com/v4/letter/k/bbe5ce/32.png) [@Kunone](https://discuss.konghq.com/u/Kunone)\
**Post date:** [May 6, 2019, 2:31am UTC](https://discuss.konghq.com/t/strip-part-of-uri/2738/5 "2019-05-06T02:31:31Z")

</div>

They already have a plugin `request-transformer-advanced` to handle such case. Although it only available with Enterprise subscription.

But anyway, really looking forward to have such `strip_path_prefix` to be available for all. Otherwise we have to create much more `services` and `routes` for the case…

---

<div class="post-metadata">

**Author:** ![pgruszecki](https://avatars.discourse-cdn.com/v4/letter/p/8c91f0/32.png) [@pgruszecki](https://discuss.konghq.com/u/pgruszecki)\
**Post date:** [July 9, 2019, 6:37pm UTC](https://discuss.konghq.com/t/strip-part-of-uri/2738/6 "2019-07-09T18:37:39Z")

</div>

It would be very useful for us.

---

<div class="post-metadata">

**Author:** ![jado](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jado](https://discuss.konghq.com/u/jado)\
**Post date:** [August 23, 2019, 7:08am UTC](https://discuss.konghq.com/t/strip-part-of-uri/2738/7 "2019-08-23T07:08:10Z")

</div>

Waiting for that feature as well.

---

<div class="post-metadata">

**Author:** ![julien-sarazin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/julien-sarazin/32/1896_2.png) [@julien-sarazin](https://discuss.konghq.com/u/julien-sarazin)\
**Post date:** [April 26, 2020, 9:26am UTC](https://discuss.konghq.com/t/strip-part-of-uri/2738/8 "2020-04-26T09:26:24Z")

</div>

Any update regarding this feature?

---

<div class="post-metadata">

**Author:** ![Michael\_Johansen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/michael_johansen/32/2335_2.png) [@Michael\_Johansen](https://discuss.konghq.com/u/Michael_Johansen)\
**Post date:** [November 1, 2020, 9:05am UTC](https://discuss.konghq.com/t/strip-part-of-uri/2738/9 "2020-11-01T09:05:35Z")

</div>

This would be very usefull. Our organization is depending on namespacing Service’s for every team, and thus this “team namespace” would be very nice if could be easily removed while preserving the rest of the path.

Meanwhile it seems this community plugin does a good job: [https://github.com/alexashley/kong-plugin-path-prefix](https://github.com/alexashley/kong-plugin-path-prefix)

Or it should be possible to do it with the [`request-transformer` Kong plugin](https://docs.konghq.com/hub/kong-inc/request-transformer/), using `config.replace.uri` and regex:

```auto
config.replace.uri=your-prefix/(\w+):$(uri_captures[1])

```

---

<div class="post-metadata">

**Author:** ![rsemlal.tas](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/rsemlal.tas/32/3091_2.png) [@rsemlal.tas](https://discuss.konghq.com/u/rsemlal.tas)\
**Post date:** [November 10, 2021, 8:47am UTC](https://discuss.konghq.com/t/strip-part-of-uri/2738/10 "2021-11-10T08:47:01Z")

</div>

Since it took me a while to figure things out, I thought sharing my solution might help

For the record, I had the same problem, I end up using:

- The plugin [GitHub - alexashley/kong-plugin-path-prefix: A Kong plugin to rewrite the upstream request path](https://github.com/alexashley/kong-plugin-path-prefix) to strip the path prefix
- The _post-function_ plugin to set the `X-Forwarded-Prefix` properly

Full example with Kong Ingress Controller

```auto
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: strip-demo-2-path-prefix
config:
  path_prefix: "/foo/"
plugin: path-prefix
---
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: set-forwarded-header
plugin: post-function
config:
  access:
    - |
      ngx.var.upstream_x_forwarded_prefix='/foo'
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: demo-2
  annotations:
    konghq.com/strip-path: "false"
    konghq.com/plugins: strip-demo-2-path-prefix,set-forwarded-header
spec:
  ingressClassName: kong
  rules:
  - http:
      paths:
      - backend:
          service:
            name: echo
            port:
              number: 80
        path: /foo/bar
        pathType: ImplementationSpecific

```

With this solution:

- Requests to `/foo/bar` are captured by Kong
- They are routed to the upstream service to the path `/bar`
- The forwarded request has the header `X-Forwarded-Prefix: /foo` (which makes the upstream service able to find out what its external url is)
