apache

Redirecting all requests to HTTPS using an .htaccess file

First, You'll want to make sure the directory you're adding the .htaccess file to is set to AllowOverride All in your httpd.conf file.

Next, create the .htaccess file with the following contents

<IfModule mod_rewrite.c>
    RewriteEngine On
    <IfModule mod_ssl.c>
      RewriteCond %{HTTPS} !=on
      RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    </IfModule>
</IfModule>

Now, assuming the .htaccess file is in your root directory, when a user visits http://localhost they will be redirected to https://localhost

more Apache posts