rewrite rule for subrequest

peterjanovsky nginx-forum at
Wed May 12 02:04:24 MSD 2010

when implementing a rewrite rule for a subrequest which is the proper way to tackle the issue

1.  write the rewrite rule in the main location (location /), the location where the subrequests are generated
2.  write the rewrite rule in the subrequest location

i am using two subrequests to concatenate the document's contents residing at the requested URL


main request

GET /path/to/files/document_1.html

i generate two subrequests allowing me to chunk the response to the client as the document's contents are large


echo_subrequest_async GET /sub1 -q $request_filename;
- where request_filename = /path/to/files/document_1.html


echo_subrequest_async GET /sub2 -q $request_filename;
- where
     request_filename = /path/to/files/document_1.html before rewrite rule
     request_filename = /path/to/files/document_2.html after rewrite rule

here is the rewrite rule i'm using

rewrite ^(_.*)$ $1_2.html break;
- so subrequest1 would go to /path/to/files/document_1/html and subrequest2 would go to /path/to/files/document_2.html

i've attempted putting the rewrite rule in the default location and also the subrequest2 location.  on my backend i am able to trace the request is coming from the subrequest2 location but the URL passed through is the original URL and not my modified URL.

i know i must be missing something in the documentation, but i'm not sure what it may be.  how do you use a modified version of the URL from subrequest1?


Posted at Nginx Forum:,85547,85547#msg-85547

More information about the nginx mailing list