Problem Description
Connect the prefix name URL to the address: http://127.0.0.1/zt/n4/, change to: http://127.0.0.1/zt/n4/
Why did you do that?
When a Web server receives a URL request with no slash at the end, for example: Http://www.360shouji.com/product, the server searches for a file named "Product" under the root directory of the Web site. If you do not treat product as a directory, then return to the default home page in the ABC directory. When a Web server receives a request with a trailing slash at the end, it is processed directly as a directory. For semantic clarity. Of course, many applications are now route rewriting paths.
Configuration Method
Add the following code to nginx.conf in the Nginx configuration file
if (-D $request _filename) {
rewrite ^/(. *) ([^/]) $ http://$host/$1$2/permanent;
}
In this way, Nginx will be judged, if the request is a folder, will automatically add/symbol at the end, if the request is a file, it will not change the original URL
Here's an explanation for this piece of code:
1,if (-D $request _filename), true if the request is a folder, to execute in the IF statement
2,rewrite is a URL rewrite operation
3,^/(.) ([^/]) $ represents a string that starts with a/symbol and is immediately followed by any character, not at the end of/, in my URL, (.) Furu:/abc/cde, ([^/]) that represents a string that is not ending with/
4,http://$host/$1$2/of the rewritten address, $host is the requested domain name, which is the first parenthesis in front, in my URL is a string of/ABC/CDE, and $ is the second in front of the parentheses, in my URL is
5,permanent says the return value is 301