linux - Nginx 重写规则而不改变 url

标签 linux url nginx webserver url-rewriting

我需要在不更改 url 的情况下为我的 nginx 服务器重写规则。 例如 : 以下链接 http://example.com/old/path/index.php?cid=XXhhHHnmmm
成为:
http://example.com/newpath/index.php?cid=XXhhHHnmmm

并指向该特定文件夹(/旧/路径)。
到目前为止,我已经尝试了以下方法,如果我尝试打开
_http://example.com/newpath:
但如果我尝试
则不起作用 _http://example.com/newpath/index.php?cid=XXhhHHnmmm

location ~ /old/path {
rewrite "/old/path" http://www.example.com/newpath$2 break;
}

我也尝试过使用 proxypass :

location /newpath {
proxy_pass http://www.example.com/old/path;
}

但仍未按预期工作。

最佳答案

尝试

location ~ ^/newpath {
    rewrite ^/newpath/(.*) /old/path/$1 break;
}

关于linux - Nginx 重写规则而不改变 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29849863/

相关文章:

linux - 拒绝脚本中的函数?

javascript - 为什么pushState() 不适用于干净的URL?

同时在fedora上运行php7和php5

nginx - 如何在 Centos 中禁用 ipv6

linux - Linux 上的 inotifywait 是否允许在超时期限内收集事件?

linux - 自动将输入提供给 Linux 命令行

linux - 如何让我的 VPS 开始使用通过 HostMonster 购买的额外磁盘空间?

javascript - 在哪里捕获运行语句中的 $location.search() 变量?为了重建国家

swift - Swift 中的 Master Detail 应用程序 - 如何将字符串转换为 URL

ruby-on-rails - 在 Rails 3 的 URL 段中允许编码斜线的最佳方式是什么?