Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

Tracy Floyd http://www.coalescedesign.com

1 total

Force traffic over HTTPS

// Force traffic over HTTPS to avoid weird session dropping issues, Also handles addition or removal of www prefix as needed for your security cert,


<IfModule mod_rewrite.c>

RewriteEngine On

  # Force removal of www
  RewriteCond %{HTTP_HOST} ^www\.(.+)$
  RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

  # (Or force addition of www depending on your cert)
  RewriteEngine On
  RewriteCond %{HTTP_HOST} !^www\.
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

  # Now Force traffic to use HTTPS
  RewriteCond %{SERVER_PORT} !443
  RewriteRule ^(.*)$ https://securesiteurl.com/$1 [R=301,L]

</IfModule>

1 total