# Dynamic Path from plugin

**URL:** <https://discuss.konghq.com/t/dynamic-path-from-plugin/701>\
**Category:** Questions\
**Created:** [March 16, 2018, 9:22am UTC](https://discuss.konghq.com/t/dynamic-path-from-plugin/701 "2018-03-16T09:22:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SirK79](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/sirk79/32/254_2.png) [@SirK79](https://discuss.konghq.com/u/SirK79)\
**Post date:** [March 16, 2018, 9:22am UTC](https://discuss.konghq.com/t/dynamic-path-from-plugin/701/1 "2018-03-16T09:22:46Z")

</div>

Hi

I am trying to write a new plugin that dynamically generates upstream url (based on header value).  
So far I successfully changed upstream host using:

ngx.ctx.balancer\_address

but I need to change path for upstream url too, do you know how can I achieve this ?  
I found somewhere that ngx.var.upstream\_url but it gives me an error:  
“variable “upstream\_url” not found for writing;”

---

<div class="post-metadata">

**Author:** ![jinwik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/jinwik/32/258_2.png) [@jinwik](https://discuss.konghq.com/u/jinwik)\
**Post date:** [March 16, 2018, 11:34pm UTC](https://discuss.konghq.com/t/dynamic-path-from-plugin/701/2 "2018-03-16T23:34:37Z")

</div>

ngx.var.upstream\_uri

---

<div class="post-metadata">

**Author:** ![SirK79](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/sirk79/32/254_2.png) [@SirK79](https://discuss.konghq.com/u/SirK79)\
**Post date:** [April 27, 2018, 7:04am UTC](https://discuss.konghq.com/t/dynamic-path-from-plugin/701/3 "2018-04-27T07:04:50Z")

</div>

Sorry for late reply but thanks 🙂 for pointing this variable. I will try it tonight and let post solution for future reference if works.

---

<div class="post-metadata">

**Author:** ![thibaultcha](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/thibaultcha/32/340_2.png) [@thibaultcha](https://discuss.konghq.com/u/thibaultcha)\
**Post date:** [April 27, 2018, 5:07pm UTC](https://discuss.konghq.com/t/dynamic-path-from-plugin/701/4 "2018-04-27T17:07:19Z")

</div>

A more thorough explanation can be found here:

> [@Changing upstream url](https://discuss.konghq.com/t/changing-upstream-url/261/2):
>
> Hi, As of 0.11.0, and as documented in the [Changelog](https://github.com/Kong/kong/blob/master/CHANGELOG.md#0110---20170816) and [Upgrade path](https://github.com/Kong/kong/blob/master/UPGRADE.md#upgrade-to-011x) of that version, the way to update the upstream URL is via the $upstream\_uri NGINX variable, accessible in the Lua-land as ngx.var.upstream\_uri. The upstream URI is now determined via the Nginx $upstream\_uri variable. Custom plugins using the ngx.req.set\_uri() API will not be taken into consideration anymore. One must now set the ngx.var.upstream\_uri variable from the Lua land. [#2519](https://github.com/Kong/kong/pull/2519) Additionally, you can access the ngx.c…

---

<div class="post-metadata">

**Author:** ![SirK79](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/sirk79/32/254_2.png) [@SirK79](https://discuss.konghq.com/u/SirK79)\
**Post date:** [July 11, 2018, 4:12pm UTC](https://discuss.konghq.com/t/dynamic-path-from-plugin/701/5 "2018-07-11T16:12:27Z")

</div>

Thanks for your response, however I had to park this plugin as we do not need it currently. Might come back to it in near future and will try out your solution.

Thanks again.
