Enforce HTTPS usage

Want to enforce SSL usage on apache2?, after having it working you only need a few mod_rewrite lines. In the case of SLES9/10, create a file /etc/apache2/conf.d/enforce.conf with the following content:

# Se indica a apache que todas las conexiones al puerto 80 deben ir al puerto 433, sin excepciones/This forces SSL usage without exceptions
<IfModule !mod_rewrite.c>
LoadModule rewrite_module /usr/lib/apache2-prefork/mod_rewrite.so
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
# La siguiente linea indica la condicion para mod_rewrite / mod_rewrite condition
ReWriteCond %{SERVER_PORT} !^443$
# Regla en caso de que la condicion anterior sea verdadera / rule applied in case the above condition is true
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</IfModule>

The exact path to mod_rewrite module can be found with “rpm -ql apache2|grep rewrite”. Now restart apache (rcapache2 restart)

Author: ciroiriarte

I'm an IT professional interested in infrastructure technologies, working as an Architect for a Service Provider present in 9 markets. Works includes technologies related to Distributed App environments, Operating Systems, OS Virtualization, SDN & VNF.

One thought on “Enforce HTTPS usage”

Leave a Reply

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