Wordpress - Howto force SSL for all requests?
A simple check for is_ssl()
should do it:
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;
}
But I would do this in .htaccess to catch images too:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
For ISS see this answer on Stack Overflow.