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?

asked Feb 7, 2015 by anonymous

1 Answer

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]
answered Feb 8, 2015 by Eric Z Ma (44,280 points)
edited Feb 9, 2015 by Eric Z Ma

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...