PHP强制http作301跳转到https代码

九月 13, 2020 by · Leave a Comment 

一般建议在php文件开头调用:

function force_http_to_https(){
	if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') return;//https access, skip
	$ssl_url='https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];//generate https url
	header("HTTP/1.1 301 Moved Permanently");
	header("Location: {$ssl_url}");
	exit;
}

——本文最后由傅老师于2020-09-13编辑过

评论


七 × 一 =