Force https using .htaccess

Oct 2, 2014 by Johan

If you want to enforce your visitors to access your site over a secure connection only, you can redirect all requests that are not secure to the secure protocol. An easy to way to do this can be accomplished with a .htaccess file containing the following lines.

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

The first line tells Apache we are going to use mod_rewrite. The second line only matches if SSL is not active on this request. If that second line matches then the third line kicks in, which simply redirects the visitor to the SSL version of the requested page.

Permalink · no comments yet · htaccess · · Johan

Johan is a 37-year-old man from The Netherlands, currently living in Germany. His interests are music, universe & space, IT-technology, quantum mechanics, physics and electronics. After high school and college he has been working on IT-support for different companies. He is a fan of science fiction and is always excited to see technology evolve from idea to reality. Especially the developments for quantum computing to real life applications and new discoveries in space can always count on his attention.

361875870


Leave a Comment

This will never be published.
You may use Markdown Syntax. HTML is not allowed.
CAPTCHA Image
Click on the image to retrieve a new verification code.