简单检查is_ssl()
应该这样做:
add_action( \'plugins_loaded\', \'wpse_2718_force_ssl\' );
function wpse_2718_force_ssl()
{
if ( is_ssl() )
return;
wp_redirect(
\'https://\' . $_SERVER[\'HTTP_HOST\'] . $_SERVER[\'REQUEST_URI\']
);
exit;
}
但我会这样做。htaccess也可以捕获图像:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
有关ISS,请参阅
this answer on Stack Overflow.