Redirect HTTP to HTTPS

Since I don’t post enough of these little tips and tricks (and because I looked for this one for like an hour last night on some customer’s site I had done this for), I’m going to start posting more nifty tips. This is a mod_rewrite rule for Apache that will take any request on normal http and redirect it to the corresponding https page. Pretty handy for stuff like online shopping carts.

RewriteEngine on
RewriteCond %{SERVER_PORT} !443 [NC]
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>