Home > internet, security, sysadmin > Apache: Force SSL for a Directory Using .htaccess and mod_rewrite

Apache: Force SSL for a Directory Using .htaccess and mod_rewrite

December 12th, 2005 Leave a comment Go to 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]

  1. No comments yet.
  1. No trackbacks yet.