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

bramvandenbulcke created an issue. See original summary.

mikeytown2’s picture

Status: Active » Fixed

Should be fine.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.