Redirect to or away from http(s) and www

Use this generator to consolidate your URLs by forcing www (or non-www) and http(s). For more information on why this is important, take a look at this post.
Example
# Examples of valid markup
# Redirect to https and non-www
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# Redirect to http and www
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{SERVER_NAME}/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]