How To Use .htaccess To Force SSL On Your Website

Using .htaccess we can do many things one of that is force your website to use an SSL (HTTP) to (HTTPS) connection, which encrypts and passes the information between a web server and the web browser.
Create and Edit .htaccess files.
Before using .htaccess we want to know about the .htaccess because even small mistakes, such as spelling mistakes or typos, in .htaccess files it makes big problem with viewing the website, In this case, before editing the .htaccess file we need to keep a backup file for .htaccess.
Once you Log in to your web server cPanel click File Manager. Then click upper right side corner settings and make sure show hidden files in selected and click save the file.
For more information about showing .htaccess hidden files, Click Here.
Once you see the file directory create or edit the .htaccess file. If you can’t see the .htaccess file create a new file, click the new file and name the file .htaccess. If you need to edit an existing .htaccess file select the file and click edit.
To force SSL for the entire website add the following code in your .htaccess file. For subdirectory, We need to create a .htaccess file in the subdirectory and add the code to force SSL.
1 2 3 |
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] |
Then click to save and close the file. Open your website in your web browser to test the change.
.htaccessawscloud serverserver
Mraj
Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts. If you have any questions let me drop an email with the article name to the following email id: [email protected]