Adding query string to redirect?

we’d like to add onto the query string an identifier of the nginx server

something like:

return 301 https://$host$request_uri?source=server1 ;

the problem is that we can’t figure out how to make this work correctly
when the url already contains query strings.

Example:
return 301 https://$host$request_uri?source=server1 ;
Good!
in /foo.bar
out /foo.bar?source=server1
Bad!
in /foo.bar?a=1
out /foo.bar?a=1?source=server1

How can we get this?

in  /foo.bar
out /foo.bar?source=server1

in   /foo.bar?a=1
out /foo.bar?a=1&source=server1

At the location/server level try:

if ($is_args) {
return 301 https://$host$request_uri&source=server1;
}

Goes here if the above is not chosen.

return 301 https://$host$uri?source=server1 ;

----appa

On Mon, Jul 01, 2013 at 05:18:47PM -0400, Jonathan V. wrote:

Hi there,

the problem is that we can’t figure out how to make this work correctly when the
url already contains query strings.

If the format difference between $request_uri and $uri is not important
to you in this case, and if the order of the arguments is not important,
then replacing

$request_uri

with

$uri?source=server1&$args

might be enough.

See Module ngx_http_core_module
for what the different variables mean.

If those conditions don’t hold, then you may need to set your extra bit
to start with ? or & depending on the existence of $args or of $is_args,
which you could do in a map.

f

Francis D. [email protected]