How to redirect all HTTP requests to HTTPS

前端 未结 26 2147
小鲜肉
小鲜肉 2020-11-22 00:40

I\'m trying to redirect all insecure HTTP requests on my site (e.g. http://www.example.com) to HTTPS (https://www.example.com). I\'m using PHP btw.

26条回答
  •  终归单人心
    2020-11-22 01:01

    Do everything that is explained above for redirection. Just add "HTTP Strict Transport Security" to your header. This will avoid man in the middle attack.

    Edit your apache configuration file (/etc/apache2/sites-enabled/website.conf and /etc/apache2/httpd.conf for example) and add the following to your VirtualHost:

    # Optionally load the headers module:
    LoadModule headers_module modules/mod_headers.so
    
    
        Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"
    
    

    https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security

提交回复
热议问题