简体   繁体   English

从重写中排除网址

[英]exclude url from rewrite

I have set my nginx server to redirect all traffic from http to https. 我已将我的nginx服务器设置为将所有流量从http重定向到https。 Now I need to have one url accessible from http. 现在,我需要从http访问一个网址。 Here is my nginx config: 这是我的nginx配置:

server {
    listen 80 default;
    server_name www.example.com example.com;


    location /example_page/ {
            return 301 http://$server_name/example_page/;
    }

    rewrite ^ https://$server_name$request_uri? permanent;
}

But this won't work. 但这是行不通的。

You can define rules for whole site and excluded url: 您可以为整个网站和排除的网址定义规则:

server {
  server_name example.com;
  listen 80;
  ...  
  # redirect any http url to https
  location / {
    return 301 https://$server_name$request_uri;
  }

  # but no redirect for this particular location:
  location /example_page/ {
    # usual site rules here (php handler etc)
  }        
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM