使用.htaccess和mod_rewrite强制SSL / https
发布时间:2020-05-25 02:31:49 所属栏目:PHP 来源:互联网
导读:本文章向大家介绍使用.htaccess和mod_rewrite强制SSL / https,需要的朋友可以参考一下。
需求: 如何使用PHP中特定的.htaccess和mod_rewrite页面强制使用SSL / https。 PHP解决方案直接借用Gordon非常全面的答案,我注意到你的问题提到强制HTTPS / SSL连接是特定于页面的。 function forceHTTPS(){ $httpsURL = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; if( count( $_POST )>0 ) die( 'Page should be accessed with HTTPS,but a POST Submission has been sent here. Adjust the form to point to '.$httpsURL ); if( !isset( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS']!=='on' ){ if( !headers_sent() ){ header( "Status: 301 Moved Permanently" ); header( "Location: $httpsURL" ); exit(); }else{ die( ' 相关内容
|