Nginx Lowercase URL and Redirection

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Nginx Lowercase URL and Redirection

zakirenish
Hi,

I am facing two issues.

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

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.

Thank you

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

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Nginx Lowercase URL and Redirection

Francis Daly
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        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx