November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

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>