For Apache
To use certbot for both a http://domain and http://www.domain use the following command:
certbot --apache -n -d domain.com -d www.domain.com --agree-tos --email admin@domain.com --redirect --expand
Without specifying both domains, you will get a certificate error for the domain not specified during creation.