Christopher Juckins

SysAdmin Tips, Tricks and other Software Tools

User Tools

Site Tools


force_https_ssl_on_a_website

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]
force_https_ssl_on_a_website.txt · Last modified: 2025/03/20 18:38 by juckins