How to make redirect from http to https

How to redirect from http to https.

  1. redirect to
  2. redirect to
  3. redirect to

Like facebook, google ??

Please help me with code in .htaccess or another


I have that covered in my mod_rewrite tutorial at including code.



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}


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!



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