【问题标题】:How to use Nginx to redirect to specific page?如何使用 Nginx 重定向到特定页面?
【发布时间】:2013-08-15 09:46:18
【问题描述】:

您好,我希望使用 Nginx 重定向到某个页面,例如: 当前域是 testing.example.com。我想要访问的页面是 testing.example.com/test 但我想要重定向的域是 t.example.com 所以:

t.example.com = testing.example.com/test

任何帮助谢谢!

【问题讨论】:

    标签: php redirect nginx


    【解决方案1】:

    如果您只想重定向所有流量,请使用以下服务器块,如果您想连接 uri,则可以在 return 语句中添加 $request_uri

    $scheme 用于在重定向到的位置保留httphttps 协议,否则您可以在不使用$scheme 的情况下将其替换为任一协议

    server {
        server_name t.example.com;
        location / {
            return 301 $scheme://testing.example.com/test;
        }
    }
    

    【讨论】:

      【解决方案2】:

      添加您的t.example.com location { } 类似:

      rewrite ^(.*) http://testing.example.com/test/$1 permanent;
      

      或者只是简单的重定向

      return 301 http://testing.example.com/test/;
      

      【讨论】:

        【解决方案3】:

        在您的 server 主机配置块中试试这个

        location /test {
           rewrite ^ $scheme://testing.example.com$request_uri permanent;
        }
        

        【讨论】:

          猜你喜欢
          • 2015-10-19
          • 1970-01-01
          • 2021-12-20
          • 1970-01-01
          • 2012-08-16
          • 1970-01-01
          • 1970-01-01
          • 2017-07-18
          • 2020-11-05
          相关资源
          最近更新 更多