【问题标题】:Nginx rewrite not working as per docsNginx 重写无法按照文档工作
【发布时间】:2014-12-10 09:00:40
【问题描述】:

我正在尝试将http://example.com/test/index.php?/Server/Search/IP_ADDRESS 重定向到http://example.com/?ip=IP_ADDRESS

尝试了以下重写规则,但是,它不起作用。

重写 ^/test/index.php?/Server/Search/(.*)$ http://example.com/?ip=$1 重定向;

这是内部用途所需要的,因为另一个 api 将检查http://example.com/?ip=IP_ADDRESS 的 IP 地址

【问题讨论】:

  • 我不明白你想要什么?
  • 我只想重定向工作:(
  • 好吧。 rewrite 仅适用于 $uri,不包含任何查询参数。

标签: nginx url-rewriting rewrite


【解决方案1】:
location = /test/index.php {
  if ($args ~ "^/Server/Search/(.+)") {
     set $sip $1;
     rewrite ^(.*)$ /?ip=$sip? redirect;
  }
}

【讨论】:

    猜你喜欢
    • 2019-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多