Auto redirect http site url to https in cpanel

Trainee Asked on October 12, 2019 in Cpanel.
Add Comment
2 Answer(s)

try to do it on your root directory .htaccess file.

# Force SSL
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

Note: It will work only if you have mod_rewrite installed on cpanel server, otherwise use php bases SSL redirect.

Reviewer Answered on October 12, 2019.
Add Comment

add the following lines of code in the index page of the site

if($_SERVER["HTTPS"] != "on")
{
header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
exit();
}

Then the site url redirected to https link

Reviewer Answered on October 12, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.