Auto redirect http site url to https in cpanel

MAK picture MAK · Apr 9, 2012 · Viewed 28.6k times · Source

Redirect the site url http to https..for this i upload .htaccess file in my cpanl public_html root directory.the code of the file as

RewriteEngine On  
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://sitename.in/$1 [R,L]

After i hosted this file also it's not redirecting my site to https protocol

Answer

Shiv Singh picture Shiv Singh · Feb 1, 2017

i am writing this answer too late but currently its working fine. So 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.