Redirect HTTP requests to HTTPS in Apache

One more short snippet, that might be useful to me in the future. If you have a website served by Apache and want your clients to only use HTTPS, you can use this mod_rewrite configuration:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]

If the server then gets any HTTP request, it will redirect the client to the same URL, but with the https scheme. This means that actual requests will be only ever served via HTTPS.

This entry was posted in Tools and tagged , , , . Bookmark the permalink.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>