Skip to content

Instantly share code, notes, and snippets.

@a1phanumeric
Created June 20, 2018 15:48
Show Gist options
  • Save a1phanumeric/42e295e2b36c0febbed71d17ca3c43d7 to your computer and use it in GitHub Desktop.
Save a1phanumeric/42e295e2b36c0febbed71d17ca3c43d7 to your computer and use it in GitHub Desktop.
PHP redirect to HTTPS if htaccess if giving you bare grief
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