Solved

Automatic re-directing a HTTP request to HTTPS

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
echo button 13 47
jQuery animation faster 1 18
Two RegEx conditions in one 3 17
Angular - ng-if worked but why like this? 5 1
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

20 Experts available now in Live!

Get 1:1 Help Now