# How to check a request is subrequest or not?

**URL:** <https://www.ruby-forum.com/t/how-to-check-a-request-is-subrequest-or-not/191915>\
**Category:** NGINX\
**Created:** [July 20, 2010, 5:09pm UTC](https://www.ruby-forum.com/t/how-to-check-a-request-is-subrequest-or-not/191915 "2010-07-20T17:09:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![elmo1349](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5e9695/32.png) [@elmo1349](https://www.ruby-forum.com/u/elmo1349)\
**Post date:** [July 20, 2010, 5:09pm UTC](https://www.ruby-forum.com/t/how-to-check-a-request-is-subrequest-or-not/191915/1 "2010-07-20T17:09:56Z")

</div>

How can I check a request is subrequest or not at the config files?

Posted at Nginx Forum:

> **[How to check a request is subrequest or not?](https://forum.nginx.org/read.php?2,110862,110862#msg-110862)**
>
> How can I check a request is subrequest or not at the config files?

---

<div class="post-metadata">

**Author:** ![elmo1349](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5e9695/32.png) [@elmo1349](https://www.ruby-forum.com/u/elmo1349)\
**Post date:** [July 20, 2010, 5:25pm UTC](https://www.ruby-forum.com/t/how-to-check-a-request-is-subrequest-or-not/191915/2 "2010-07-20T17:25:11Z")

</div>

Is these any variable just like the IS\_SUBREQ Flag in apache?

[http://httpd.apache.org/docs/2.2/mod/mod\_rewrite.html](http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html)

IS\_SUBREQ  
Will contain the text “true” if the request currently being  
processed is a sub-request, “false” otherwise. Sub-requests may be  
generated by modules that need to resolve additional files or URIs in  
order to complete their tasks.

Posted at Nginx Forum:

> **[Re: How to check a request is subrequest or not?](https://forum.nginx.org/read.php?2,110862,110872#msg-110872)**
>
> How can I check a request is subrequest or not at the config files?

---

<div class="post-metadata">

**Author:** ![elmo1349](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5e9695/32.png) [@elmo1349](https://www.ruby-forum.com/u/elmo1349)\
**Post date:** [July 20, 2010, 8:45pm UTC](https://www.ruby-forum.com/t/how-to-check-a-request-is-subrequest-or-not/191915/3 "2010-07-20T20:45:24Z")

</div>

Hi,

> How can I check a request is subrequest or not at the config files?

if (r != r-\>main) {  
/\* this is subrequest \*/  
}

Best regards,  
Piotr S. \< [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \>

---

<div class="post-metadata">

**Author:** ![elmo1349](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5e9695/32.png) [@elmo1349](https://www.ruby-forum.com/u/elmo1349)\
**Post date:** [July 21, 2010, 2:43am UTC](https://www.ruby-forum.com/t/how-to-check-a-request-is-subrequest-or-not/191915/4 "2010-07-21T02:43:09Z")

</div>

Hi Piotr,

I want to define a request in nginx config file, such as,  
/etc/nginx/nginx.conf.

For example:

server {

if($IS\_SUBREQ){  
do something  
}

}

Posted at Nginx Forum:

> **[Re: How to check a request is subrequest or not?](https://forum.nginx.org/read.php?2,110862,111127#msg-111127)**
>
> How can I check a request is subrequest or not at the config files?

---

<div class="post-metadata">

**Author:** ![elmo1349](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5e9695/32.png) [@elmo1349](https://www.ruby-forum.com/u/elmo1349)\
**Post date:** [July 21, 2010, 3:00am UTC](https://www.ruby-forum.com/t/how-to-check-a-request-is-subrequest-or-not/191915/5 "2010-07-21T03:00:43Z")

</div>

Hi,

> I want to define a request in nginx config file, such as,  
> /etc/nginx/nginx.conf.

Ah, sorry. I’ve missed the “at the config files” part.

I don’t think this is possible with nginx.conf.

Best regards,  
Piotr S. \< [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \>

---

<div class="post-metadata">

**Author:** ![elmo1349](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5e9695/32.png) [@elmo1349](https://www.ruby-forum.com/u/elmo1349)\
**Post date:** [July 21, 2010, 3:22am UTC](https://www.ruby-forum.com/t/how-to-check-a-request-is-subrequest-or-not/191915/6 "2010-07-21T03:22:58Z")

</div>

As there are two variables in http core module:

$request\_uri  
This variable is equal to the _original_ request URI as received from  
the client including the args. It cannot be modified. Look at $uri for  
the post-rewrite/altered URI.

$uri  
This variable is equal to current URI in the request (without arguments,  
those are in $args.) It can differ from $request\_uri which is what is  
sent by the browser. Examples of how it can be modified are internal  
redirects, or with the use of index.

They are different at subrequest or internal redirects, but it is  
impossible to define is subrequest or not at server{} part ?

Can I compare some variables to do so?

Posted at Nginx Forum:

> **[Re: How to check a request is subrequest or not?](https://forum.nginx.org/read.php?2,110862,111134#msg-111134)**
>
> How can I check a request is subrequest or not at the config files?
