To really be universal, I'm using this:
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'
|| $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://';
header('Location: '.$protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit;
I like $_SERVER['REQUEST_URI']
because it respects mod_rewrite and/or any GET variables.
https detection from https://stackoverflow.com/a/2886224/947370