September 2025
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

September 2025
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Forcing HTTP traffic over HTTPS using Apache

Forcing HTTP traffic over HTTPS using Apache

I recently was required to redirect all traffic for a domain over an HTTPS connection. Using the Apache’s .htaccess files and the RewriteEngine, this task is trivial.

Insert this block of code into your .htaccess file at the root of your domain. This will redirect at HTTP traffic to use an HTTPS connection instead:

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

You also need to make sure you have this line in your httpd.conf file (installed by default on most Linux Distributions)

LoadModule rewrite_module modules/mod_rewrite.so

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>