Created
November 4, 2015 18:01
-
-
Save israelshirk/d6b6672212ae5a3f3469 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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