为api/rest到rest/v1重写Nginx URL

为api/rest到rest/v1重写Nginx URL,nginx,mod-rewrite,nginx-location,Nginx,Mod Rewrite,Nginx Location,当前的API端点如下 domain.com/api/rest/[actual_module_routing_path, eg. cms/page/home] 在新系统中,这必须类似于 domain.com/rest/V1/$1 无论使用何种HTTP方法(GET、POST、PUT、DELETE),它都必须工作。在nginx主机配置中尝试类似的东西,但我无法让它工作,非常感谢您的帮助 location /api/rest { #Rewrite $uri=/api/rest/ back t

当前的API端点如下

domain.com/api/rest/[actual_module_routing_path, eg. cms/page/home]
在新系统中,这必须类似于

domain.com/rest/V1/$1
无论使用何种HTTP方法(GET、POST、PUT、DELETE),它都必须工作。在nginx主机配置中尝试类似的东西,但我无法让它工作,非常感谢您的帮助

location /api/rest {
    #Rewrite $uri=/api/rest/ back to just $uri=/rest/V1/$1
    rewrite ^/api/rest/(.*)$ /rest/V1/$1 break;
}
location ~ /api/rest/(.*) 
{ 
rewrite ^(.*)$ /rest/v1/$1 redirect; 
}