nginx url重写的语法是什么

nginx url重写的语法是什么,nginx,Nginx,我有一个应用程序正在运行 http://localhost/subfolder/myapp/ 如何创建重写规则,以便将以下URL重定向到我的应用程序 http://localhost/subfolder/myapp/route1 http://localhost/subfolder/myapp/route2 http://localhost/subfolder/myapp/routeN ...anyother routes after http://localhost/subfolder/my

我有一个应用程序正在运行

http://localhost/subfolder/myapp/
如何创建重写规则,以便将以下URL重定向到我的应用程序

http://localhost/subfolder/myapp/route1
http://localhost/subfolder/myapp/route2
http://localhost/subfolder/myapp/routeN
...anyother routes after http://localhost/subfolder/myapp/

添加此块nginx规则

location ~ /subfolder/myapp/.* {
  redirect from here
}

在Nginx中,您可以使用服务器块中的
返回执行重写:

location ~ /subfolder/myapp/route(.*) {
    return 301 http://localhost/subfolder/myapp;
}
这似乎有效:

rewrite ^/subfolder/myapp/.+$ /subfolder/myapp last;

服务器将不会以此启动。(我在这一点上没有ngnix的经验)我犯了太多错误,我尝试了这个
location~/subfolder/myapp/*{return 301http://localhost/subfolder/myapp$request_uri;}
和此
位置~/subfolder/myapp/*{return 301http://localhost/subfolder/myapp}
@techguy2000好的,我编辑了这个问题。只需删除
$request\u uri
。但是,这将丢弃url之后的任何内容。例如,如果您调用:
http://localhost/subfolder/myapp/route2/test
它将重定向到
http://localhost/subfolder/myapp
未通过
测试
。我仍然收到太多重定向。请注意,我的/路线(*)可以是任何东西。这就是我尝试的“location~/subfolder/myapp/(.*){return 301;}”