How can browser-specific behavior affect PHP-based SSL redirection and how can it be mitigated?

Browser-specific behavior can affect PHP-based SSL redirection by not properly interpreting the header redirects. To mitigate this issue, you can use JavaScript to force the browser to redirect to the secure URL.

<?php
if ($_SERVER['HTTPS'] != 'on') {
    header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    exit();
}
?>