Redirect 使用Nginx重定向和替换

Redirect 使用Nginx重定向和替换,redirect,nginx,Redirect,Nginx,在nginx中,我很难让它正常工作: 我正在尝试将这样的url字符串重写为: http://domainname/n/xxx = > http://domaindomain/x/xxx 我只想将“n”改为“x” 我试过: location /n/ { rewrite ^/n/(.*)$ /x/? last; } 感谢您的帮助您需要使用以下规则: rewrite ^/n/(.*)$ /x/$1 permanent; (.*)将在/n/部分之后捕获您的URL,$1将在目标URL

在nginx中,我很难让它正常工作:

我正在尝试将这样的url字符串重写为:

http://domainname/n/xxx = > http://domaindomain/x/xxx
我只想将“n”改为“x”

我试过:

location  /n/ {
    rewrite ^/n/(.*)$ /x/? last;
}

感谢您的帮助

您需要使用以下规则:

rewrite ^/n/(.*)$ /x/$1 permanent;
(.*)
将在
/n/
部分之后捕获您的URL,
$1
将在目标URL中放置相同的内容


使用
permanent
关键字将使用301 HTTP状态代码重定向用户

在您的示例中,更改域名只能使用重定向。但在你的代码中我看到了重写。你想做什么?我不想更改域名,我们想更改域名后的url模式,例如,你想让用户看到
新的关键字吗?