Force HTTPS/SSL on a website

Using .htaccess:

cd to directory you want to protect and edit .htaccess such as the following:

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

-or-

SSLRequireSSL

then:

service httpd restart

Using httpd.conf:

Edit /etc/httpd/conf/httpd.conf such as the following:

# Force <DIR> to use SSL
RewriteEngine on
RewriteCond   %{SERVER_PORT}  !^443$
RewriteRule ^/<DIR>(.*)$ https://%{HTTP_HOST}/<DIR>$1 [L,R]

Example:

# Force Nagios to use SSL
RewriteEngine on
RewriteCond   %{SERVER_PORT}  !^443$
RewriteRule ^/nagios(.*)$ https://%{HTTP_HOST}/nagios$1 [L,R]