简体   繁体   English

NGINX 将 URL 保留在 /location/some-path 并提供 /location/?

[英]NGINX keep URL at /location/some-path and serve /location/?

Is this possible?这可能吗?

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

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

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

Is there a particular name for this type of action also?这种类型的动作也有特定的名称吗?

You can use nginx redirection here -您可以在此处使用 nginx 重定向 -

location = /location/any-path {
   return 301 /location;
  }

You want to proxy_pass the request to another url and then proxy_redirect to alter the url displayed to the client.您希望将请求代理传递给另一个proxy_pass ,然后proxy_redirect以更改显示给客户端的 url。

Something like this:是这样的:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM