proper way to redirect from http to https w/query string notifier

Gena Makhomed gmm at csdoc.com
Tue Mar 24 18:10:08 UTC 2015


On 24.03.2015 17:33, Jonathan Vanasco wrote:

> i need to redirecting from http to https,
> and append a "source" attribute for tracking
> (we're trying to figure out how the wrong requests are coming in)

Probably you can do such tracking just looking at Referer request header

> this seems to work:
> 			if ($query_string){
> 				return 301 https://$host$request_uri&source=server1 ;
> 			}
> 			return 301 https://$host$request_uri?source=server1 ;
>
> I'm just wondering if there is a more appropriate way

Yes, you can use $uri variable and rewrite directive for this:

http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite
| If a replacement string includes the new request arguments,
| the previous request arguments are appended after them.

  rewrite ^ https://$host$uri?source=server1 permanent;

-- 
Best regards,
  Gena



More information about the nginx mailing list