Link to home
Start Free TrialLog in
Avatar of Loganathan Natarajan
Loganathan NatarajanFlag for India

asked on

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
Avatar of honestman31
honestman31

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Pratima
Pratima
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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/
No points for this comment, please but the answer from pratima_mcs, above, is exactly what I use.
Avatar of Loganathan Natarajan

ASKER

Thanks