Apache Redirect to Secure Link

Posted by on December 20, 2011 in Apache, Web Servers | 0 comments

If you have a directory that you want to force users into an SSL connection, the easiest way is to use a .htaccess file if your host allows it. The following will force any page to redirect to https:// if they aren’t on it already.

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

If you want to exclude a directory or filename specifically, then just add in another rewrite condition as shown below.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/.*FullOrPartOfFileNameOrDirectoryHere.* [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>