Bludit force http to https
1.Set "Site URL" from “http” to “https”
The redirect from http to https can often be set in the admin panel,just set http to https at "Settings" > "General" > "Advanced" > "Site URL".
If it cannot be modified in the admin panel, then it is necessary to directly modify the "URL" of "site. php" in the "blcontent/databases" directory.
2.Modify "index.php" in themes and add force HTTP to HTTPS code
Open the "index.php" file in the theme directory,and add the code to force HTTP to HTTPS:
<?php
// 强制HTTPS重定向
if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off') {
$redirect_url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirect_url);
exit();
}
?>
注意:务必确保这段代码在最顶部,前面不能有任何字符(包括空格和换行)。
3.Modify “. htaccess" and add force HTTP to HTTPS code
Optional methods: Open the ". htaccess" file in the root directory of the website,and add the code to force HTTP to HTTPS:
# rules if your server setup allows HTTPS.
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
注意:一般完成第二步修改即可。且添加htaccess规则虽形式上可以实现强制转向,但是实际运行中对URL的HTTPS转换是不完全的。
Done!