Skip to content

Instantly share code, notes, and snippets.

@israelshirk
Created November 4, 2015 18:01
Show Gist options
  • Save israelshirk/d6b6672212ae5a3f3469 to your computer and use it in GitHub Desktop.
Save israelshirk/d6b6672212ae5a3f3469 to your computer and use it in GitHub Desktop.
<?php
add_action( 'template_redirect', 'nlp_ssl_template_redirect', 1 );
function nlp_ssl_template_redirect() {
if ( !is_ssl() && ! is_admin() ) {
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http:' ) ) {
wp_redirect( preg_replace( '|^http://|', 'https://', $_SERVER['REQUEST_URI'] ), 301 );
exit();
} else {
wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );
exit();
}
}
if (is_ssl()) {
header("Strict-Transport-Security: max-age=31536000;");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment