Home  >  Q&A  >  body text

How to exclude specific addresses in nginx's rewrite rules

How can rewrite rules exclude specific paths?
For example, the entire site uses HTTPS, but /XXX/ does not use HTTPS
By rewriting ^(.*) https://$host$1 permanent; you can all jump to the https address, but among them http What should I do if I don’t want to force HTTPS for all content at ://abc.com/XXX/? Because some clients do not support HTTPS, they cannot all be banned at once.

仅有的幸福仅有的幸福2712 days ago716

reply all(2)I'll reply

  • 某草草

    某草草2017-05-16 17:09:55

    Just put it in front, refer to the code

    location /XXX/ {
       index index.php;
    }
    
    location / {
        rewrite ^(.*) https://$host permanent;
    }

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-16 17:09:55

    First use location to exclude the exception path, and then do rewrite.

    reply
    0
  • Cancelreply