简体   繁体   中英

exclude url from rewrite

I have set my nginx server to redirect all traffic from http to https. Now I need to have one url accessible from http. Here is my nginx config:

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)
  }        
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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