How to force SSL with ' .htaccess '?

You can force an HTTPS connection on your website by adding these rules in your any website's .htaccess file:

  1. Log in to your MotionHost control panel.
  2. Click the File Manager icon located in the file section.
  3. From the file manager pop-up settings, choose the folder you would like to open, most often the WebRoot is (public_html/www).
  4. Under the Preferences, make sure the Show hidden files is checked.
  5. Click the Submit button.
  6. The File Manager will open in a new tab or window.
  7. Look for the .htaccess file in the list of files. You may need to scroll to find this file.             

Then proceed to the steps below, which will explain how to edit the file to add protection:

  1. Right-click on the .htaccess file and select the Edit option.
  2. A pop-up message will appear, then click the Edit button.
  3. At the top of the file, insert the following code:
RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteCond %{REQUEST_URI} /[SSL Requested page]/ 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
  1. Click the Save Changes button towards the top right corner of your screen.
  2. Check your website to ensure it is functioning as expected.

    (If that doesn't work, you can try using this default cPanel code.)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

(Change the example.com with your own domain)

Was this answer helpful? 0 Users Found This Useful (0 Votes)