首页 > 解决方案 > NGINX 将 URL 保存在 /location/some-path 并提供 /location/?

问题描述

这可能吗?

用户输入https://mywebsite.com/location/any-path

Nginx 运行https://mywebsite.com/location/

URL 显示https://mywebsite.com/location/any-path

这种类型的动作也有特定的名称吗?

标签: nginxurlredirecturl-rewritingnginx-reverse-proxy

解决方案


您希望proxy_pass将请求发送到另一个 url,然后proxy_redirect更改显示给客户端的 url。

像这样的东西:

location ~ /location/(.+) {
    resolver 8.8.8.8;
    proxy_pass https://mywebsite.com/location/index.php;
    proxy_redirect /location/ /location/$1/;
}

推荐阅读