I prefer to use https + www for my blog.
Presumably you have already set up a canonical 301 redirect to https://www.example.com?
will I have to add all these 4 types of addresses to webmaster tools?
Yes, this is recommended. It then allows you to set the preferred domain (www vs non-www) and to check for any errors (eg. a non-canonical getting indexed etc.).
to what specific URL do I need to submit the sitemap.xml file with?
The canonical property. ie. https://www.example.com.
Does the same goes with xml file also?
What (additional?) XML file?
Do I need to submit all xml files to each domain separately or just a one?
Once you've added all properties to Google Search Console (formerly Google Webmaster Tools) then you concentrate just on the canonical property. You can periodically check the other properties to make sure there are no errors etc.
UPDATE:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
This code is not sufficient. This is a 302 (temporary) redirect from HTTP to HTTPS only. It will not redirect the non-canonical https://example.com (ie. non-www to www). You would need something like the following:
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
All requests that are either port 80 (ie. not HTTPS) or are not www then redirect to the canonical URL. You need to explicitly include the 301 status with the R flag, otherwise it defaults to a 302. (But it is a good idea to test first with a 302 to make sure it's working, since this won't be cached.) You also don't need the <IfModule> wrapper.
<IfModule mod_rewrite.c>RewriteEngine OnRewriteCond %{SERVER_PORT} 80RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]</IfModule>if that's the 301 redirect. Is there any problem with this bunch of code? – Anjana Nilupul Jan 02 '17 at 11:35