I am trying to force my website to redirect http traffic to the https site and I have verified that the htaccess file is getting accessed but the redirect is not occurring. I have a valid cert for the site and the https version works fine but whether I type in www.mywebsite.com or http://www.mywebsite.com or website.com I still get taken to the HTTP version. Any suggestions?
.htaccess file
# Use PHP56
AddHandler application/x-httpd-php56 .php
# Always Redirect to HTTPS
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} ^(www\.)?mywebsite\.com$ [NC]
RewriteRule ^$ https://mywebsite.com%{REQUEST_URI} [R=301,L]
Now, you know how to edit the .htaccess file, let’s redirect HTTP to HTTPS using the edit .htaccess file method. 1. Redirect All Web Traffic Add this code below the existing code in your .htaccess file. 2. Redirect Only a Specific Domain Add this code to redirect a specific domain to use HTTPS. 3. Redirect Only a Specific Folder
You can use .htaccess to redirect your site on HTTPS. What is .htaccess? Simply put, it is a configuration file. If you want to migrate to ‘https’ from ‘http’, you need to make a few changes in your .htaccess file. A .htaccess file comes with necessary instructions that can help you do that.
Method #2: Open the FTP program, and use the Edit function to edit the file remotely. Method #3: Go to cPanel and open the File Manager to edit the .htaccess file. (I have written this method in detail)
A .htaccess file comes with necessary instructions that can help you do that. Therefore, .htaccess offers a way to make changes in the configurations on a per-directory basis. How to edit a .htaccess file?
I use this on my website and it redirects to HTTPS and not HTTP. There is also a great explanation here: Best Practice: 301 Redirect HTTP to HTTPS (Standard Domain)
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I have solved this problem by adding this code snippet, make sure it is at the beginning of the file .htaccess:
# Force HTTPS on all pages
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With