mobile logo

HTTP to HTTPS via mod_rewrite

posted on October 12, 2007 / IN Apache / Quick Tip / 4 Comments

To redirect a website from http -> https I utilized mod_rewrite. And created a .htaccess file with the following contents.

$ cat .htaccess
Options FollowSymLinks
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$1

This can be useful if you need to ensure all access to your site, is done via HTTPS.

By admin

Tagged With


Please use the form to leave a comment

    • Mirge
      Posted on October 19, 20093:51 pm Reply

      Thank you, this was PERFECT… I tried another popular rewrite, but it wouldn’t work.. this one worked for me.

    • Saad
      Posted on June 1, 201010:31 am Reply

      I only want to run some of the pages on SSL and want site to switch back to non SSL when accessed other pages.

      How can I do this?

      e.g.* should run on SSL but any other URL should be on http.


Page 1 of 1

Leave a comment.