Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In my settings.php file, I'm using the snippet (provided by advagg) to default to https and this is working well:
if ((isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')
|| (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
|| (isset($_SERVER['HTTP_HTTPS']) && $_SERVER['HTTP_HTTPS'] == 'on')
) {
$_SERVER['HTTPS'] = 'on';
}
I have another snippet in my settings.php to require www (for SEO purposes). I use this snippet for easier updating (versus a .htaccess solution).
// Require www
if ($_SERVER['HTTP_HOST'] == 'example.com') {
header('HTTP/1.0 301 Moved Permanently');
header('Location: https://www.example.com'. $_SERVER['REQUEST_URI']);
exit();
}
The website is working well but I'm wondering if it's ok to combine these two snippets?
Comments
Comment #2
mikeytown2 CreditAttribution: mikeytown2 commentedShould be fine.