Last active
July 27, 2023 18:09
-
-
Save jigarius/a799cd9f9e13d20eed32f15291e08d19 to your computer and use it in GitHub Desktop.
Drupal Force HTTPS Redirect with PHP
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 | |
/** | |
* @file | |
* Always redirect to HTTPS. | |
*/ | |
if ( | |
php_sapi_name() !== 'cli' && | |
strtoupper($_SERVER['HTTPS'] ?? '') !== 'ON' && | |
($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? NULL) !== 'https' | |
) { | |
header('HTTP/1.0 301 Moved Permanently'); | |
header("Location: https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment