Welcome! Log In Create A New Profile

Advanced

Get rid of args from $request_uri

Posted by chilly_bang 
chilly_bang
Get rid of args from $request_uri
August 08, 2017 11:50AM
Hi

I want to build a construction like

location ~* {
if ($args ~ *) {
add_header Link "<$scheme://$http_host$request_uri>; rel=\"canonical\"";
}
}
but need to get rid of argues from $request_uri. The goal is from any url
with parameters to point with canonical auf non-parameter url counterpart.
I've realized a method to get rid of argues from $request_uri, like this:

map $request_uri $request_uri_path {
"~^(?P<path>[^?]*)(\?.*)?$" $path;
}

I Need an advice - how are both snippets to put together?

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

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
c0nw0nk
Re: Get rid of args from $request_uri
August 08, 2017 02:50PM
why don't you use

$uri $is_args $args

This will build the URL like.

index.php ? arguement=value&moreargs=morevalue


$request_uri will always output the full URL. Not individual segments of
it.

If you want the first part of the url only just use $uri on its own.

http://nginx.org/en/docs/http/ngx_http_core_module.html#var_uri

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,275930,275936#msg-275936

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
chilly_bang
Re: Get rid of args from $request_uri
August 08, 2017 04:10PM
c0nw0nk Wrote:
-------------------------------------------------------
> why don't you use
>
> $uri

Is it not so, that $uri will output an encoded url?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,275930,275937#msg-275937

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Zhang Chao
Re: Get rid of args from $request_uri
August 08, 2017 04:10PM
On 8 August 2017 at 22:02:32, chilly_bang ([email protected])
wrote:

c0nw0nk Wrote:
-------------------------------------------------------
> why don't you use
>
> $uri

Is it not so, that $uri will output an encoded url?


$uri is always the one decode once time and merge the slash(if you enable
it).
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Lucas Rolff
Re: Get rid of args from $request_uri
August 08, 2017 06:00PM
I use the set_misc module from openresty and do something like:

if ($request_uri ~ "([^/?]*)(?:\?|$)") {
set $double_encoded_filename $1;
}
set_unescape_uri $encoded_uri $double_encoded_uri;

Can probably be improved, but I can use $encoded_uri and get the reslt you’re looking for c0nw0nk.



From: nginx <[email protected]> on behalf of Zhang Chao <[email protected]>
Reply-To: "[email protected]" <[email protected]>
Date: Tuesday, 8 August 2017 at 16.07
To: "[email protected]" <[email protected]>
Subject: Re: Get rid of args from $request_uri





On 8 August 2017 at 22:02:32, chilly_bang ([email protected]<mailto:[email protected]>) wrote:
c0nw0nk Wrote:
-------------------------------------------------------
> why don't you use
>
> $uri

Is it not so, that $uri will output an encoded url?

$uri is always the one decode once time and merge the slash(if you enable it).
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login