Automatic re-directing a HTTP request to HTTPS

Hello all experts.

I have only one page that needed to be secured by a Secure Certificate only recently.

Unfortunately over time, that page has been referenced to from a number of different places on the site.

Is there a way via PHP to force that one page always use "https://" every time someone accesses it WITHOUT having any error messages popping up warning visitors...???

Thanx in advance.

--d.
driven_13Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Scott Fell, EE MVEConnect With a Mentor Developer & EE ModeratorCommented:
<?php
if($_SERVER["HTTPS"] != "on") {
    $newurl = "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
    header("Location: $newurl");
    exit();
    }
?>
0
 
jessegivyDeveloperCommented:
I don't believe you want to accomplish this with PHP but rather in your web server configuration. In apache there is certainly a way to enforce "https://" over "http://" using mod rewrite.
0
 
Vimal DMSenior Software EngineerCommented:
.htaccess file would be help full,

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTPS} !on
RewriteRule !/(doctor|client)(/.*)?$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.