Auto redirect http site url to https in cpanel
Asked Answered
A

3

8

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

Adrenal answered 9/4, 2012 at 16:16 Comment(0)
A
3

I added 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

Adrenal answered 10/4, 2012 at 10:9 Comment(0)
T
17

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.

Trypanosomiasis answered 1/2, 2017 at 18:19 Comment(1)
Work great for me on .htaccess of Wordpress installation with cPanel. Thanks!Pazice
H
4

I just modified the .htaccess file in the first part of the answer for my Wordpress site to redirect http:// to https://. I didn't need to modify the index page and it worked fine for me without it. Thanks to the author of that as it completed my quest for a secure certificate migration.

My complete file .htaccess file looked like this for me. I suggest making a local copy as I broke my site a few times before I found the right answer for me here:

#RewriteCond %{HTTP_HOST} ^yoursite\.com [NC]
#RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Options +FollowSymlinks

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [R,L]
Hasa answered 1/7, 2012 at 22:57 Comment(0)
A
3

I added 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

Adrenal answered 10/4, 2012 at 10:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.