How do I add a slash at the end of a url?

  • 0
    Hello. On a multilingual site, I try to add a slash at the end of the url on the main site to get
    I use this directive but it doesn't work:
    location ~ "^/[a-z]{2}[\s]" {
        return 301 $1/;

    Now url in this form
    What could be the mistake?
    Nginx Isaac Hunt, May 19, 2020

  • 1 Answers
  • 0
    It doesn't need a whitespace character [\ s] , but the end of the line $ .

    And also highlight the subpattern to which the variable $ 1 refers with parentheses.

    location ~ "^/([a-z]{2})$" {
    return 301 /$1/;

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!