案例:Redirect /product to new domain (www.newsite.com).
server{
...
location /product {
rewrite ^/product(.*)$ https://www.newsite.com/$1 redirect;
}
...
}
rewrite – rewrite command tells NGINX to change one or more URLs that match a given pattern (e.g /product) to another URL.
^/product – URL paths that start with /product. You can change it to another URL as you need it.
(.*) – match one or more characters. In our case, it means anything that follows /product
$ – end of string
$1 – URL part after /product
redirect – tells NGINX to redirect to another URL. It can also be a new domain, subdomain, subdirectory or even URL.