Created
December 16, 2018 12:31
-
-
Save hanicker/f2eb353bb716ca4f82f9da378b46e998 to your computer and use it in GitHub Desktop.
Simple mu-plugin (move to wp-content/mu-plugins/cloudflare-flexible-ssl-redirect-loop-fix.php) to fix cloudflare redirect and optionally force https
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 | |
| // Fix https detection | |
| if( (isset($_SERVER['HTTP_CF_VISITOR']) && (strpos($_SERVER['HTTP_CF_VISITOR'], 'https') !== false)) || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)) ){ | |
| $_SERVER['HTTPS'] = 'on'; | |
| } | |
| // Also force https (optional) | |
| if(empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off"){ | |
| $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | |
| header('HTTP/1.1 301 Moved Permanently'); | |
| header('Location: ' . $redirect); | |
| exit(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment