Nginx Lowercase URL and Redirection

Francis Daly francis at daoine.org
Sun Apr 19 18:47:53 UTC 2020


On Sat, Apr 18, 2020 at 11:05:36AM -0400, mustafa.chapal wrote:

Hi there,

> First, URLs like www.example.com/new-arrivalS which include a character like
> hyphen are not triggering on the following location.

Works for me. What other location do you have that does handle this
request?

==
  location ~ [A-Z] {
    return 200 "Does match A-Z\n";
  }
  location / {
    return 200 "Does not match A-Z\n";
  }
==
$ curl http://127.0.0.1/new-arrivalS
Does match A-Z
$ curl http://127.0.0.1/new-arrivals
Does not match A-Z


> Second, URLs like www.example.com/dealS?p=2 get redirected to
> www.example.com/deals instead of www.example.com/deals?p=2
> 
> location ~ [A-Z] {
>       return 307 $scheme://$host$my_uri_to_lowercase;
>     }
> 
> Kindly help me resolve both the issues.

Either change your $my_uri_to_lowercase to include the query string;
or change the return line to be

  return 307 $scheme://$host$my_uri_to_lowercase$is_args$args;

http://nginx.org/r/$is_args and http://nginx.org/r/$args for details.

Good luck with it,

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list