WebFaction Https Redirects

Yet another thing to file under “beating my head against a wall for hours before figuring out something simple"—argh!

I wanted to redirect all requests to https for a WebFaction-hosted site, and wasn’t having any luck with the normal:

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

I was getting "too many redirects” errors. After digging around I found mention of https redirects on this page with this code:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Note the %{HTTP:X-Forwarded-SSL} instead of %{HTTPS}.

Well howdy-doody it works now, hallelujah, back to more important coding matters like my giant SVG head navigation.