To redirect http traffic to https in Apache, create a .htaccess file with the following content:

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

Place the .htaccess file in your website directory and that should be it.

NOTE: The rewrite module in Apache must be enabled for this to work. To check whether it is enabled, open your httpd.conf and make sure the line below is not commented:

LoadModule rewrite_module modules/mod_rewrite.so

If you’re running Apache on Windows, you won’t be able to create a file with a filename that starts with “.” so you will have to tell Apache to look for another file. To do so, simply open your httpd.conf and change the line:

AccessFileName .htaccess

to

AccessFileName ht.acl .htaccess

Instead of naming the file .htaccess, name it ht.acl. Restart Apache and it should work.