Need to redirect all traffic to https

This works for me:

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

If the traffic is coming in over non-SSL HTTP, then redirect to the HTTP equivalent of whatever page the user was originally trying to access. It also doesn’t involve any mod_rewrite options, so it’s easy to read.

Side rant: why does everyone feel the need to explicitly set the HTTP code of the redirect and mark one of their rewrites as the “last” one? Seriously, I’ve seen dozens of same-looking htaccess rules in just the last few days.

Leave a Comment