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
That was very helpful. Thank you!
Very helpful information. Thank you!