Search code examples
nginxnginx-location

how to make nginx location match path both with slash and without slash?


currently i have this location in my nginx file, it does not work with http://mydomain/ab/cd. How can i make the browser to go to the same page when user type both http://mydomain/ab/cd and http://mydomain/ab/cd/?

location /ab/cd/ {
}

Solution

  • The fastest, in terms of performance, is simply two exact locations:

    location = /ab/cd {
       ...
    }
    
    location = /ab/cd/ {
       ...
    }