I want to redirect URLs without slash to the path with trailing slash.
So /some-url to /some-url/
And the rest of the URLs, like
/some-url.xml
/some-url?
/some-url?q=v
/some-url/
Should stay without redirection.
location ~ ^([^.\?]*[^/])$ {
try_files $uri @addslash;
}
location @addslash {
return 301 $uri/;
}
Unfortunately this doesn't really work. Because url /some-url?q=v gets redirected to /some-url/
Could you suggest how to change regular expression to make it work?
解决方案
This should solve the problem:
location / {
if ($request_uri ~ ^([^.\?]*[^/])$) {
return 301 $1/;
}
try_files $uri $uri/ /index.php$is_args$args;
}