S
S
Sergey Erin2020-11-19 19:08:25
Nginx
Sergey Erin, 2020-11-19 19:08:25

How to add slash at the end of url?

Hello. On a multilingual site, I try to add a slash at the end of the url on the main site to make it work . I mysite.com/en/
use this directive, but it does not work:

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

Now the url looks like this mysite.com/en
. What could be wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-11-19
@artalexs

It does not need a space character [\s], but the end of the line $.
And also highlight the subpattern referenced by the $1 variable with parentheses.

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question