nginx url重写的语法是什么

时间:2017-04-05 21:35:53

标签: nginx

我有一个在

运行的应用
http://localhost/subfolder/myapp/

如何创建重写规则,以便将以下网址重定向到我的应用程序?

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

3 个答案:

答案 0 :(得分:0)

添加此块nginx规则

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

答案 1 :(得分:0)

在Nginx中,您可以使用服务器块内的return进行重写:

location ~ /subfolder/myapp/route(.*) {
    return 301 http://localhost/subfolder/myapp;
}

答案 2 :(得分:0)

这似乎有效:

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