I need to redirect non-www urls to www url for both http and https urls. I tried following rules in web.config.
Other answers here are unnecessary long, here's the rule i use (just copy and paste) :
This will redirect to the www version while preserving the HTTP and HTTPS protocol
Hope this helps.