Nginx使用返回301重定向

Rom*_*nko 0 nginx nginx-location

我需要从URL进行永久重定向:

https://SiteName.com/shop/forklift-tires/XXX/
to
https://SiteName.com/shop/tires/forklift-tires/XXX/
Run Code Online (Sandbox Code Playgroud)

要么

https://SiteName.com/shop/forklift-tires/YYY/
to
https://SiteName.com/shop/tires/forklift-tires/YYY/
Run Code Online (Sandbox Code Playgroud)

我该如何使用下面的结构呢?

location *something* {
        return 301 *something*;
}
Run Code Online (Sandbox Code Playgroud)

从文章“陷阱和常见错误”中我了解到,最好使用return而不是rewrite

hch*_*ung 5

更新(正确答案)

根据您的评论,尝试以下操作:

location  ~ ^shop/forklift-tires/(.*) {
    return 301  /shop/tires/forklift-tires/$1 ;
}
Run Code Online (Sandbox Code Playgroud)

先前的答案(对这个问题的误解表示抱歉)

创建另一个服务器指令,如下所示:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name Sitename.com;
    return 301 https://$host$request_uri;
}
Run Code Online (Sandbox Code Playgroud)

http://SiteName.com/ *的所有流量都将重定向到https://SiteName.com/ *。