Amazon S3, SSL & Craft

Ian Ebden
By Ian Ebden ·

Looks like this article was written a while ago. Some of the ideas and techniques described may now be outdated. Just sayin’.

So I'm working on a site at the moment on a secure server, and I'm redirecting all http requests to https (via .htaccess). All good except the site's images are on Amazon S3 (http), and I was running into issues switching between protocols on local and production; plus some browsers issue mixed content warnings for mixed protocols on the same page.

{{ image.getUrl(yourTransformName)|replace({'http:':''}) }}

Hooking up Amazon's CloudFront service to your S3 account can fix this, but it's a costly solution. Another option is to configure SSL for your S3 bucket via CloudFlare. But here's a super-simple super-quick workaround that costs nothing.

<img src="//s3-eu-west-1.amazonaws.com/bucketname/_480x240_crop_center-center/filename.jpg?mtime=20150914151236" alt=""/>

With no protocol specified the browser will just use the current one – http on local or https on production. Amazon already have SSL on their S3 domains so your image will load fine on either protocol.