After installing the SSL certificate, your website is accessible via HTTP and HTTPS protocols. However, it is better to use only HTTPS, because it encrypts and secures the data of your site.

How to force HTTPS using .htaccesss

JOne of the many functions you can perform via .htaccess is redirect 301, which permanently redirects the old URL to the new one.
You can activate the function to force HTTPS to all incoming traffic by following these steps:

    • 1. Go to File Manager on cPanel and open .htaccess within the public_html directory. If you can't find it, be sure to make it or discover it.

If you do not know how to do this, visit the following page:
How to enable .htaccess file visibility?

    • 2. Enter the following code:
Switching from HTTP to HTTPS
  • RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
  • IMPORTANT: Make sure that the RewriteEngine On line does not repeat twice. In case the line already exists, simply copy the rest of the code without it.

Conclusion

Congratulations! you have successfully edited your .htaccess file and redirected all HTTP traffic to HTTPS, a secure version of your site. Depending on the platform on which you developed the website, there may be alternative ways to enable this feature.

In one of the next posts we will show some more methods of redirection via .htaccess file.

To learn more about HTTP and HTTPS please visit the following page:

CONTACT US