How to make redirect from http to https

How to redirect from http to https.

  1. redirect http://example.com to https://www.example.com
  2. redirect http://www.example.com to https://www.example.com
  3. redirect https://example.com to https://www.example.com

Like facebook, google ??

Please help me with code in .htaccess or another

Raj,

I have that covered in my mod_rewrite tutorial at http://dk.co.nz/seo including code.

Regards,

DK

I believe if you add this to the .htaccess file located in your web root it should do the trick…

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

mikey,

The last time I looked (admittedly, quite some time ago), {HTTPS} was either {null{ or on so you should use !on or, better yet, %{SERVER_PORT} !^443$. Then, why bother capturing the {REQUEST_URI} (with ‘(.*)’) if you’re not going to use it. Personally, I use .? which will match anything.

RewriteEngine on
RewriteCond %{SERVER PORT} ^80$
RewriteRule .? https://%{HTTP_HOST}%{REQUEST_URI}

Good effort just the same!

Regards,

DJK

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.