Reputation: 775
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
Upvotes: 8
Views: 29387
Reputation: 7211
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.
Upvotes: 17
Reputation: 41
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]
Upvotes: 4
Reputation: 775
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
Upvotes: 3