# Trouble with $uri in subrequest

**URL:** <https://www.ruby-forum.com/t/trouble-with-uri-in-subrequest/245843>\
**Category:** NGINX\
**Created:** [July 17, 2013, 10:52pm UTC](https://www.ruby-forum.com/t/trouble-with-uri-in-subrequest/245843 "2013-07-17T22:52:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [July 17, 2013, 10:52pm UTC](https://www.ruby-forum.com/t/trouble-with-uri-in-subrequest/245843/1 "2013-07-17T22:52:14Z")

</div>

Hi there,

i’m having trouble getting the request\_uri via lua in a subrequest.

ngx.var.uri will always return the uri of the parent request whereas  
something like ngx.req.get\_uri\_args will return the correct args for the  
subrequest.

any ideas on how to get the subrequets uri? or am i missing something  
here?

i’m using 1.4.1, thanks in advance

Thomas

Posted at Nginx Forum:

> **[Trouble with $uri in subrequest](https://forum.nginx.org/read.php?2,240968,240968#msg-240968)**
>
> Hi there, i'm having trouble getting the request\_uri via lua in a subrequest. ngx.var.uri will always return the uri of the parent request whereas something like ngx.req.get\_uri\_args will return the correct args for the subrequest. any ideas on how...

---

<div class="post-metadata">

**Author:** ![ThomasLohner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@ThomasLohner](https://www.ruby-forum.com/u/ThomasLohner)\
**Post date:** [July 18, 2013, 1:22am UTC](https://www.ruby-forum.com/t/trouble-with-uri-in-subrequest/245843/2 "2013-07-18T01:22:23Z")

</div>

Hello!

On Wed, Jul 17, 2013 at 1:51 PM, ThomasLohner wrote:

> i’m having trouble getting the request\_uri via lua in a subrequest.
> 
> ngx.var.uri will always return the uri of the parent request whereas  
> something like ngx.req.get\_uri\_args will return the correct args for the  
> subrequest.
> 
> any ideas on how to get the subrequets uri? or am i missing something here?

Could you please give a minimal example that can reproduce this issue?

Apparently, the following example works as expected on my side with  
ngx\_lua 0.8.4 + nginx 1.4.1 on Linux x86\_64:

```
location = /sub {
    internal;
    content_by_lua '
        ngx.say("sr uri: ", ngx.var.uri)
    ';
}

location = /main {
    echo_subrequest GET /sub;
}

```

Accessing /main with curl yields

```
$ curl localhost:1985/main
sr uri: /sub

```

That is, ngx.var.uri evaluates to the URI of the subrequest, /sub, not  
that of the parent request, /main.

Best regards,  
-agentzh

---

<div class="post-metadata">

**Author:** ![ThomasLohner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@ThomasLohner](https://www.ruby-forum.com/u/ThomasLohner)\
**Post date:** [July 18, 2013, 10:40am UTC](https://www.ruby-forum.com/t/trouble-with-uri-in-subrequest/245843/3 "2013-07-18T10:40:18Z")

</div>

oh my…

i was fooled by $request\_uri which returns the parent uri. i understand  
that  
this is intended behavior.

sorry!

Posted at Nginx Forum:

> **[Re: Trouble with $uri in subrequest](https://forum.nginx.org/read.php?2,240968,240978#msg-240978)**
>
> Hi there, i'm having trouble getting the request\_uri via lua in a subrequest. ngx.var.uri will always return the uri of the parent request whereas something like ngx.req.get\_uri\_args will return the correct args for the subrequest. any ideas on how...
