How to force a website to use https by htaccess settings?

I would like my site to be accessed by https only. How to force a website to use https by htaccess settings by redirecting http requests to the corresponding https ones?

You can check the method of redirecting http to https at:

https://www.systutorials.com/qa/1033/how-to-redirect-http-to-https-in-apache-with-mod_rewrite

If you would like to have a 301 redirect, you can use the following .htaccess file:

# force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *