Rewrite save original url

When rewriting a url with the rewrite directive, is it possible to save
the
original url in a request header for the downstream handler?

Similar to the X-Rewrite-URL header built in to ISAPI rewrite.
Or in Apache, I can do it with something like:

#== Capture original uri and query string into environment variable so
it
can be put in a header
#== Match non-empty query string
RewriteCond %{QUERY_STRING} (^.+$)
RewriteRule (.*) $1 [E=x-rewrite-url:$1?%1]

If this is possible in nginx, how would I do it?

Thanks

I think you could do something like this:

# save old uri + arguments:
set $original_uri $uri$is_args$args;
# perform rewrite:
rewrite ^(.*)$ /new_uri/index.php;

# later on, in location defined downstream handler, add:
proxy_set_header X-Rewrite-URL $original_uri;

Never try it out, but hope it helps!

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

Hello!

On Tue, Sep 21, 2010 at 03:21:31PM -0400, Arthur B. wrote:

RewriteRule (.*) $1 [E=x-rewrite-url:$1?%1]

If this is possible in nginx, how would I do it?

http://wiki.nginx.org/NginxHttpCoreModule#.24request_uri

Maxim D.

Thank you Maxim and tqvn2004! I placed the following in my location
directive:

proxy_set_header X-Rewrite-URL $request_uri;

And it worked!

I found a way. Never used “set” variables before… need to study nginx
more :stuck_out_tongue:

Just before the rewrites i’m saving the original $uri to a variable

set $cleanuri $uri;

which in turn i pass to the proxy via headers

proxy_set_header X-Rewrite-FullURI $request_uri;
proxy_set_header X-Rewrite-CleanURI $cleanuri;

p.s: all my content rewrites are using “last”;

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

Is it possible to have only the original URL without the arguments?

I know two ways but i rather use a ready made variable from nginx.
PHP and rewrite with regex

Thanks in advance

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs