Redirect Non-WWW to WWW (and WWW to Non-WWW) With .htaccess, Including HTTPS

Pick one hostname and send everything else to it with a single 301. These .htaccess rules handle www, non-www and HTTPS in one hop, with notes for WordPress and sites behind a proxy.