Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

How can I redirect to https from http?

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
Loganathan Natarajan
Asked:
Loganathan Natarajan
1 Solution
 
honestman31Commented:
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
 
Pratima PharandeCommented:
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
 
Pratima PharandeCommented:
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
 
Ray PaseurCommented:
No points for this comment, please but the answer from pratima_mcs, above, is exactly what I use.
0
 
Loganathan NatarajanLAMP DeveloperAuthor Commented:
Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now