How do I redirect a directory path in nginx? In order to solve this problem, this article introduces the corresponding analysis and answer in detail. I hope it can help more partners who want to solve this problem to find a more simple and easy way.

It is the easiest way to modify root mapping to realize nginx directory access redirection, which is recommended.
<pre class="brush:py;"> Location / image { Root / folderName } </pre>
Example of nginx configuration code:
<pre class="brush:py;"> Location / image { Rewrite ^ / image/ (. *) $/ folderName/image/$1 last } </pre>
Example configuration:
<pre class="brush:py;"> Location / image { Alias / folderName/image; # write the absolute path here } </pre>
Example configuration:
<pre class="brush:py;"> Location / image { Rewrite ^ / image/ (. *) $http://dashidan.com/folderName/image/$1; } </pre>
Example configuration:
<pre class="brush:py;"> If ($request_uri ~ * ^ (/ image)) { Rewrite ^ / image/ (. *) $/ folderName/image/$1 last } </pre>
and the following four points:
Exact matching will be the first to be processed. If an exact match is found, nginx stops searching for other matches.
Normal character matching, regular expression rules and long block rules will be matched first with the query That is, if the match also needs to see if there is a regular expression match and a longer match.
^ ~ only this rule is matched, and nginx stops searching for other matches, otherwise nginx will continue to process other location instructions.
Finally, match the instructions with "~" and "~ *". If the corresponding match is found, nginx stops searching for other matches. When there is no regular expression or no regular expression is matched, then the most matching verbatim matching instruction will be used.
<pre class="brush:py;"> Location = / {
[configuration A] } Location / {
[configuration B] } Location ^~ / images/ {
[configuration C] } Location ~*. (gif|jpg|jpeg) ${
[configuration D] } </pre>
This is the answer to the question about how to redirect the directory path in nginx. I hope the above content can be of some help to you, if you still have a lot of doubts to be solved. You can follow the billionaire Cloud Industry Information Channel to learn more about it.