Solved

How can I redirect to https from http?

Posted on 2012-12-26
5
316 Views
Last Modified: 2012-12-27
I have a website hosted in godaddy and purchased SSL (https) support for one year.  when I add custom https with my pages it works fine. How can I redirect or set by default when I access my site to go with https?

for example someone type, http://www.test.com  to go with https://www.test.com
0
Comment
Question by:Loganathan Natarajan
[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
5 Comments
 
LVL 10

Expert Comment

by:honestman31
ID: 38722852
add the following to .htaccess  file
( at the top )
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

Open in new window

0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 250 total points
ID: 38722862
if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == ""){
    $redirect = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    header("Location: $redirect");
}

refer
http://stackoverflow.com/questions/5106313/redirecting-from-http-to-https-with-php
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38722863
if ($_SERVER['SERVER_PORT']!=443)
{
      $url = "https://". $_SERVER['SERVER_NAME'] . ":443".$_SERVER['REQUEST_URI'];
      header("Location: $url");
}

refer
http://blog.cnizz.com/2007/05/14/php-force-redirect-from-http-to-https/
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 38724270
No points for this comment, please but the answer from pratima_mcs, above, is exactly what I use.
0
 
LVL 36

Author Closing Comment

by:Loganathan Natarajan
ID: 38725945
Thanks
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

691 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