How To Redirect HTTPS To HTTP Or HTTP To HTTPS From HostGator Hosting

I am using HostGator Hosting, I would like to know how to redirect https to http url or http to https url

You can try following methods to redirect https to http or http to https url for your HostGator Hosting

.htaccess

http to https

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

https to http

RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

PHP

http to https

if($_SERVER["HTTPS"] != "on"){
    $host = $_SERVER['HTTP_HOST'];
    $request_uri = $_SERVER['REQUEST_URI'];
    $new_url = "https://" . $host . $request_uri;
    header( "HTTP/1.1 301 Moved Permanently" );
    header( "Location: $new_url" );
    exit;
}

https to http

if($_SERVER["HTTPS"] == "on"){
    $host = $_SERVER['HTTP_HOST'];
    $request_uri = $_SERVER['REQUEST_URI'];
    $new_url = "http://" . $host . $request_uri;
    header( "HTTP/1.1 301 Moved Permanently" );
    header( "Location: $new_url" );
    exit;
}

cPanel

http to https

Home >> Domains >> Redirects >> Add a redirect

0 0 votes
Article Rating
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Andrea
Andrea
5 years ago

That was very helpful. Thank you!

Kannan
Kannan
2 years ago

Very helpful information. Thank you!