从您的代码中提取,我将如下重构:
function bhww_ssl_template_redirect() {
$redirect_url=\'\';
if ( shapeSpace_check_https() ) {
if ( 0 === strpos( $_SERVER[\'REQUEST_URI\'], \'http\' ) ) {
$url = $_SERVER[\'REQUEST_URI\'];
$not_allowed = array(\'https://www\', \'https://\');
foreach($not_allowed as $types) {
if(strpos($url, $types) === 0) {
$redirect_url = str_replace($types, \'http://\', $url);
}
}
} else {
$redirect_url =\'http://\' . $_SERVER[\'HTTP_HOST\'] . $_SERVER[\'REQUEST_URI\'];
}
$redirect_url = !empty($redirect_url)?$redirect_url:$url;
wp_redirect($redirect_url, 301 );
exit();
}
}
将其添加到
.htaccess
重定向www->非www的规则
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
重定向https->http
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
但要使其工作,您需要有一个有效的SSL,否则将向用户显示“恐怖屏幕”。