Created
April 23, 2014 22:22
-
-
Save martynchamberlin/11234552 to your computer and use it in GitHub Desktop.
In case you need to force HTTPS on every single page of a WordPress site, here's how.
This file contains 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 | |
$using_ssl = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || $_SERVER['SERVER_PORT'] == 443; | |
add_action('wp', 'check_ssl'); | |
function check_ssl() | |
{ | |
// All pages must be https. Redirect to https if not already | |
if (! $using_ssl) | |
{ | |
header('HTTP/1.1 301 Moved Permanently'); | |
header('Location: https://' . $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']); | |
exit; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment