Solved

Automatic re-directing a HTTP request to HTTPS

Posted on 2013-01-10
3
257 Views
Last Modified: 2013-01-16
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.
0
Comment
Question by:driven_13
3 Comments
 
LVL 12

Expert Comment

by:jessegivy
ID: 38765454
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
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 38765623
<?php
if($_SERVER["HTTPS"] != "on") {
    $newurl = "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
    header("Location: $newurl");
    exit();
    }
?>
0
 
LVL 7

Expert Comment

by:Vimal DM
ID: 38766132
.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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question