How to automatically redirect http to https in Apache

I will share 2 ways to achieve this:

  1. Using mod_rewrite. Add these directives to your configuration file:
  2. RewriteEngine On
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [L,R]

  3. Using Redirect. Add these directives to your configuration file:

    SSLRequireSSL
    Redirect permanent /secure https://www.domain.com/secure

References:
Joseph Scott’s Blog
KarKomaOnline

10 thoughts on “How to automatically redirect http to https in Apache

  1. I add this code in last of the htaccess file.URL chnage to https,but files are not opened.Please send reply as early as possible

  2. This is extremely exciting, You are an excessively qualified tumblr. We have registered the feed and turn into in place to get inside search of extra of the superb submit. Furthermore, I’ve provided your web site during my myspace

  3. I’m very pleased to discover this website.

    I want to to thank you for your time just for this fantastic read!!
    I definitely enjoyed every bit of it and i also have
    you book-marked to check out new stuff in your blog.

Leave a reply to Rob Cancel reply