Jump to content

Page won't redirect to HTTPS once SSL is actually applied to the site


dsince1984

Recommended Posts

This is probably some silly mistake but I can't figure out why this code isn't working. I put this at the top of my php page:

 

<?php
$https_url = 'https://somesite.com';
if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'off' )
{
header('location: ' . $https_url);
exit;
}
else if ( !isset( $_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] == 443 )
{
header('location: ' . $https_url);
exit;
}
?>

 

When I was just trying this code out it worked and redirected to https. No errors no infinite loops...it worked perfectly. However, once our server guy actually applied the SSL to the page, the code stopped working and I get the error "The page must be viewed over a secure location." It throws the error before it processes anything on that page. I found the code online on another help forum and it worked for everyone else, so what am I doing wrong? I also tried a different version of the code that also works for everyone else but got the same error. Thanks for your help!

Link to comment
Share on other sites

Yeah, I figured it out. Our server guy was requiring the encryption so it didn't care what I had on a page. If the original URL wasn't https it would complain. Once he just applied SSL to the page but unchecked the box requiring it, it started working.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.