Solved

Automatic re-directing a HTTP request to HTTPS

Posted on 2013-01-10
3
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 53

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
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 …

705 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