在nginx中重定向URL时遇到问题

在nginx中重定向URL时遇到问题,nginx,redirect,http-status-code-301,Nginx,Redirect,Http Status Code 301,我正在尝试设置一个Nginx重定向,其中domain.com/story/urlname将重定向到domain.com/clientstories/urlname。基本上需要从一个子路径重定向到另一个子路径。我尝试了以下操作,但始终将我重定向到domain.com/clientstories(.*我缺少什么 location /story/(.*) { return 301 $scheme://$server_name/clientstories$1; } location块缺少正则表

我正在尝试设置一个Nginx重定向,其中
domain.com/story/urlname
将重定向到
domain.com/clientstories/urlname
。基本上需要从一个子路径重定向到另一个子路径。我尝试了以下操作,但始终将我重定向到
domain.com/clientstories(.*
我缺少什么

location /story/(.*) {
    return 301 $scheme://$server_name/clientstories$1;
}

location
块缺少正则表达式运算符和URI开头的锚。
return
语句缺少
clientstories
后面的分隔符,因为它不是捕获的一部分

使用正则表达式
位置的示例

location ^/story(/.*)$ {
    return 301 /clientstories$1$is_args$args;
}
location /story/ {
    rewrite ^/story(/.*)$ /clientstories$1 permanent;
}
使用前缀
位置的示例

location ^/story(/.*)$ {
    return 301 /clientstories$1$is_args$args;
}
location /story/ {
    rewrite ^/story(/.*)$ /clientstories$1 permanent;
}
正则表达式位置是按顺序计算的,优先于前缀位置,因此配置中是否存在其他位置可能很重要。有关详细信息,请参阅