Add the following in location in the configuration file:Code
If (-d $ request_filename ){
Rewrite ^/(. *) ([^/]) $ http: // $ host/$1 $2/permanent;
}
in this way, nginx will make a judgment. If a folder is requested, the/symbol will be automatically added at the end. If a file is requested, the original URL is not changed.
The following explains the code:
1, if (-d $ request_filename), if the request is a folder, it is true, and it is executed in the IF statement
2, rewrite is the URL rewriting operation
3, ^ /(. *) ([^/]) $ indicates a string that starts with a slash (/) followed by any character and does not end with a slash (/). In my URL ,(. *) represents wordpres, ([^/]) represents S
4, http: // $ host/$1 $2/Represents the rewritten address, $ host is the requested domain name, $1 is the content in the first bracket, and in my URL, wordpres $2 is the content in the second bracket, in my URL is S
5, permanent indicates, the return value is 301