Nathan Witt

Extensibly Redirecting to HTTPS in Apache

December 28, 2012

I often find myself Googling apache config snippets and now that I'm managing a server myself, HTTPS is useful pretty much everywhere. Here is a rewrite that will work in either .htaccess or a vhost declaration to redirect traffic to HTTPS with minimal URL hard-coding.

RewriteEngine On  
RewriteCond %{HTTPS} !=on  
RewriteRule ^/?(.\*) https://%{SERVER\_NAME}/$1 \[R,L\]