How to redirect all HTTP requests to HTTPS

前端 未结 26 2202
小鲜肉
小鲜肉 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 00:45

    The Apache docs recommend against using a rewrite:

    To redirect http URLs to https, do the following:

    
        ServerName www.example.com
        Redirect / https://www.example.com/
    
    
    
        ServerName www.example.com
        # ... SSL configuration goes here
    
    

    This snippet should go into main server configuration file, not into .htaccess as asked in the question.

    This article might have come up only after the question was asked and answered, but seems to be the current way to go.

提交回复
热议问题