Get rid of args from $request_uri

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Get rid of args from $request_uri

blason
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
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get rid of args from $request_uri

blason
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
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get rid of args from $request_uri

blason
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
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get rid of args from $request_uri

Zhang Chao



On 8 August 2017 at 22:02:32, chilly_bang ([hidden email]) 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
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get rid of args from $request_uri

Lucas Rolff-2

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 <[hidden email]> on behalf of Zhang Chao <[hidden email]>
Reply-To: "[hidden email]" <[hidden email]>
Date: Tuesday, 8 August 2017 at 16.07
To: "[hidden email]" <[hidden email]>
Subject: Re: Get rid of args from $request_uri

 

 

 

 

On 8 August 2017 at 22:02:32, chilly_bang ([hidden email]) 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
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Loading...