Rewrite rule for subrequest

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

example

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

subrequest1

echo_subrequest_async GET /sub1 -q $request_filename;

  • where request_filename = /path/to/files/document_1.html

subrequest2

echo_subrequest_async GET /sub2 -q $request_filename;

  • where
    request_filename = /path/to/files/document_1.html before rewrite
    rule
    and
    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?

peter

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,85547,85547#msg-85547

clarification to above question

i know parameter “-q” passes query string parameters

what i’m looking to do is

  1. create a variable within the conf
  2. assign it request_filename
  3. parse the new variable using a regular expression or basic string
    manipulation

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,85547,85548#msg-85548

On Wed, May 12, 2010 at 6:04 AM, peterjanovsky [email protected]
wrote:

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.

Could you try out the $echo_request_uri variable?

http://wiki.nginx.org/NginxHttpEchoModule#.24echo_request_uri

Hope this helps :slight_smile:

-agentzh