diff --git a/services/s3.inc b/services/s3.inc
index da236f6..6b968eb 100755
--- a/services/s3.inc
+++ b/services/s3.inc
@@ -881,13 +881,16 @@ class StorageS3 extends StorageContainer implements StorageContainerInterface {
       $base_url .= $this->settings['cloudfront_domain'];
     }
     else {
-      $base_url .= $this->settings['bucket'];
-      // If the bucket is a CNAME alias, the full domain name is not required.
-      // There is no point in disabling this for HTTPS as it cannot work either
-      // way. Only a single level of subdomain matching is supported by a
-      // wildcard certificate.
-      if (!$this->settings['cname']) {
-        $base_url .= '.s3.amazonaws.com';
+      if ($https && strpos($this->settings['bucket'], '.') !== false) {
+        $base_url .= 's3.amazonaws.com/' . $this->settings['bucket'];
+      }
+      else {
+        $base_url .= $this->settings['bucket'];
+        // If the bucket is a CNAME alias, the full domain name is not required unless we are
+        // serving over https.
+        if (!$this->settings['cname'] || $https) {
+          $base_url .= '.s3.amazonaws.com';
+        }
       }
 
       if ($this->access_control) {
