Avatar of Loganathan Natarajan
Loganathan Natarajan
Flag 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
PHPWeb Languages and StandardsScripting Languages

Avatar of undefined
Last Comment
Loganathan Natarajan

8/22/2022 - Mon
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
Pratima

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Pratima

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/
Ray Paseur

No points for this comment, please but the answer from pratima_mcs, above, is exactly what I use.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Loganathan Natarajan

ASKER
Thanks