Apache: Force SSL for a Directory Using .htaccess and mod_rewrite
December 12th, 2005
No comments
To force SSL on a given directory using .htaccess, use the following code. It requires mod_rewrite enabled in Apache. Adjust the path in the RewriteRule to match the full qualified URL of the HTTPS-domain.
RewriteEngine On
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
I am Software Engineer and partly self-employed. I develop mainly for Windows on the Microsoft .NET platform, but also C++, Java, and sometimes Python and PHP for web applications. I also consider myself a Linux enthusiast. (