【问题标题】:nginx.conf redirecta a full urlnginx.conf 重定向一个完整的 url
【发布时间】:2017-05-11 20:14:24
【问题描述】:

我想使用 nginx 重定向一个完整的 url。 这不起作用:

server {
    listen       80;
    server_name  www.domain1.com www.domain2.com www.domain3.com ;

if ($http_host$request_uri ~ www.domain2.com/hello.html) {
    rewrite ^  google.com  permanent;
   }

}

这样做的正确方法是什么?
我怀疑变量 $http_host$request_uri 是否可以匹配该地址。

【问题讨论】:

    标签: nginx url-rewriting nginx-location


    【解决方案1】:

    显然if 不能很好地处理表达式。我会像这样重写你的配置:

    server {
        listen       80;
        server_name  www.domain1.com www.domain2.com www.domain3.com;
    
        set $full_url $http_host$request_uri;
        if ($full_url ~ ^www\.domain2\.com/hello\.html) {
           return 301 https://google.com;
        }
    }
    

    对你来说可能为时已晚,但它解决了我的问题,我希望它可以帮助别人......

    【讨论】:

      猜你喜欢
      • 2022-11-16
      • 1970-01-01
      • 2016-08-21
      • 2012-05-13
      • 1970-01-01
      • 1970-01-01
      • 2011-06-17
      • 2020-11-24
      • 1970-01-01
      相关资源
      最近更新 更多