【问题标题】:Nginx Url Rewrite IneffectiveNginx Url Rewrite 无效
【发布时间】:2019-11-30 02:28:10
【问题描述】:

我有以下路径:

http://localhost:8080/user/restReport

我需要以下重写:

http://localhost:8080/user/testReport

在 nginx.conf 中试过这个:

server {
    listen 8080;
    server_name  localhost;
    access_log  logs/localhost.access.bear.log ;

        location = /user/restReport 
        { 
            rewrite ^/testReport?$ /restReport break;           
        } 
}

但是第一个 get 一直指向它的原始路径。 基于这种重写方法尝试了不同的尝试,但没有任何反应。

【问题讨论】:

  • 你需要重写restReport,在你重写你重写TESTreport。
  • 已经试过了..不行。

标签: nginx url-rewriting


【解决方案1】:
 server {
    listen 8080;
    server_name  localhost;
    access_log  logs/localhost.access.bear.log ;

        location = /user/restReport 
        { 
            rewrite ^/restReport?$ /testReport break;           
        } 
 }    

【讨论】:

  • 解释,发布的代码的作用以及它如何解决问题中的问题,很少不能改善答案。
【解决方案2】:

您的位置声明与一个 URI 完全匹配(即/user/restReport)。

您的重写语句完全匹配两个 URI(即 /testReport/testRepor)。

由于 rewrite 语句包含在 location 语句中,因此 rewrite 永远不会看到匹配的 URI。

【讨论】:

  • 我不明白。
  • 正则表达式^/testReport?$ 与URI /user/restReport 不匹配,这就是rewrite 不会发生的原因。
猜你喜欢
  • 2012-03-20
  • 1970-01-01
  • 1970-01-01
  • 2016-01-04
  • 2020-12-07
  • 2014-03-16
  • 2022-11-24
  • 2019-07-16
  • 1970-01-01
相关资源
最近更新 更多