The situation is: you have an web application or URL that you would like to force your users (or yourself) to use the secure https protocol rather than the unencrypted http protocol. This is easy to do with Apache and .htaccess.

Create or add to the .htaccess file in the root of the web directory you would like to force redirect for. Add the following lines:

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

This says that if https is off, reload the page at the same location using HTTPS instead.

Technorati Tags: , , ,

Subscribe to comments via RSS 2.0 feed.
This post has 2 comments. Add your own.

Comments

barf - 16 Jun 08 at 22:09:33

Thanks, worked a treat. I’d tried lots of RewriteCond using server-port but couldn’t get it to work.

Jim - 22 Aug 08 at 09:46:06

This is just the tip I needed. Thanks!

Trackbacks