nginx rewrite
时间: 2023-08-31 10:10:37 浏览: 95
Nginx rewrite is a feature that allows you to modify the URL of a request before it is processed by the server. It is used to change the structure of a URL, redirect users to a different page or location, and to handle dynamic URLs.
The syntax for a rewrite rule in Nginx is as follows:
```
rewrite regex replacement [flag];
```
- `regex` is the regular expression that matches the original URL
- `replacement` is the new URL or location to which the request should be rewritten
- `flag` is an optional parameter that specifies additional behavior for the rewrite rule, such as whether or not to perform a permanent redirect
For example, the following rewrite rule redirects all requests for `example.com/about` to `example.com/about-us`:
```
rewrite ^/about$ /about-us permanent;
```
In this case, `^/about$` is the regular expression that matches requests for the `/about` page, and `/about-us` is the new location to which the request should be redirected. The `permanent` flag indicates that a 301 redirect should be used, which tells search engines that the page has permanently moved to a new location.
阅读全文