Solved

How can I redirect to https from http?

Posted on 2012-12-26
5
307 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
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 108

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

896 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