Skip to content

Instantly share code, notes, and snippets.

@jigarius
Last active July 27, 2023 18:09
Show Gist options
  • Save jigarius/a799cd9f9e13d20eed32f15291e08d19 to your computer and use it in GitHub Desktop.
Save jigarius/a799cd9f9e13d20eed32f15291e08d19 to your computer and use it in GitHub Desktop.
Drupal Force HTTPS Redirect with PHP
<?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