How to Force HTTPS using .htaccess

How to Force HTTPS using .htaccess

How to Force HTTPS using .htaccess

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

Go to File Manager in your hosting panel and open .htaccess inside the public_html folder. If you can’t locate it, make sure to create or unhide it.

Scroll down to find RewriteEngine On and insert the following lines of code below it:

RewriteEngine On 
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Save the changes.

 

Conclusion

Congratulations! you have successfully edited your .htaccess file and redirected all HTTP traffic to HTTPS, the safe version of your website. Depending on the platform where you developed your website, there could be alternative methods to enable this feature. For example, you can configure your WordPress or PrestaShop site to work with HTTPS using plugins.

If you have any tips, tricks, or suggestions that you want to share, we are looking forward to seeing them in the comments!


You might also like



Comments

    No comments found. Be the first


Leave a comment

Your name and email address will not be stored in the browser and your email will not be published.