Solved

Automatic re-directing a HTTP request to HTTPS

Posted on 2013-01-10
3
252 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now