在nginx中重写URL而不重定向

在nginx中重写URL而不重定向,nginx,rewrite,Nginx,Rewrite,我正在尝试使用nginx创建一个重写,该重写将更改显示的URL,而不实际重定向到它。例如:http://example.com/item/rest-of-path将变成http://example.com/folder/rest-of-path。我一直在使用nginx.conf中的不同版本的代码: location ~ /example { rewrite ^/example/(.*) /folder/$1 last; } 但这似乎并不奏效。你知道我哪里做错了吗?我承认我对服务器端重写一

我正在尝试使用nginx创建一个重写,该重写将更改显示的URL,而不实际重定向到它。例如:
http://example.com/item/rest-of-path
将变成
http://example.com/folder/rest-of-path
。我一直在使用nginx.conf中的不同版本的代码:

location ~ /example {
   rewrite ^/example/(.*) /folder/$1 last;
}

但这似乎并不奏效。你知道我哪里做错了吗?我承认我对服务器端重写一般来说还是相当陌生。

试试这个。无需将其放在
位置
块下,也不要忘记重新加载nginx

rewrite     ^/example/(.+)$     /folder/$1 last;
试试这个:

location ~ /example {
   rewrite ^/example/(.*) /folder/$1 break;
}
使用
break

这不会“在不实际重定向到URL的情况下更改显示的URL”。