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

Advertisements

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s