Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto redirect http site url to https in cpanel

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

like image 322
MAK Avatar asked Apr 09 '12 16:04

MAK


2 Answers

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.

like image 105
Shiv Singh Avatar answered Oct 21 '22 01:10

Shiv Singh


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]
like image 21
Jeff Avatar answered Oct 21 '22 00:10

Jeff