How can I force users to access my page over HTTPS instead of HTTP?

前端 未结 21 970
礼貌的吻别
礼貌的吻别 2020-11-28 01:15

I\'ve got just one page that I want to force to be accessed as an HTTPS page (PHP on Apache). How do I do this without making the whole directory require HTTPS? Or, if you s

21条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 01:47

    http://www.besthostratings.com/articles/force-ssl-htaccess.html

    Sometimes you may need to make sure that the user is browsing your site over securte connection. An easy to way to always redirect the user to secure connection (https://) can be accomplished with a .htaccess file containing the following lines:

    RewriteEngine On 
    RewriteCond %{SERVER_PORT} 80 
    RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
    

    Please, note that the .htaccess should be located in the web site main folder.

    In case you wish to force HTTPS for a particular folder you can use:

    RewriteEngine On 
    RewriteCond %{SERVER_PORT} 80 
    RewriteCond %{REQUEST_URI} somefolder 
    RewriteRule ^(.*)$ https://www.domain.com/somefolder/$1 [R,L]
    

    The .htaccess file should be placed in the folder where you need to force HTTPS.

提交回复
热议问题