Amazon S3, SSL & Craft.

Looks like this article is pretty old. Some of the information and/or techniques may now be obselete. Just sayin’
Amazon S3, SSL & Craft on DesignKarma

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.

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.

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

All I'm doing is using the Twig 'replace' filter to strip the protocol off the file url so the browser request ends up looking like:

<img src="//" 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.

Let us help tell your story.

Ready to inject some karma into your project?

Get started