Force SSL with .htaccess & mod_rewrite
If you are already using mod_rewrite and want to force all traffic to go through SSL you can add following rule into your htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
<IfModule mod_ssl.c>
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# Your own rewrite rules here
</IfModule>
By putting the rule in the <IfModule mod_ssl.c>
tag I can disable mod_ssl on my local server and use http while forcing SSL on my live server which has a SSL certificate
Written by Mark Vaughn
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#