Craft hasn't done this prior (or maybe I just noticed), but I'm currently battling double slashes in URLs returned from {{ asset.getUrl() }}.

The issue appears when I create an Assets field and set the following settings to that field:

Restrict uploads to a single folder (true)
Upload location: [source:Images] somefolder/somesubfolder

Calling {{ asset.getUrl() }} on an asset from this field returns the following URL:


Notice that the double slash appears inside the path specified in the field's settings – /uploads/images/ is the source path.

This happens both for Asset fields that are inside Matrix fields, and standalone fields. It also happens regardless if I use named transforms, inline transforms or no transforms (getUrl(false)).

If the source configuration should prove relevant somehow, here's the setup:

I've got an asset source (local folder) called Images configured like this:

File System Path: {imagePath}/
URL: {imageUri}/

{imagePath} and {imageUri} are environment variables, set to $_SERVER['DOCUMENT_ROOT'] . "/uploads/images" and "/uploads/images", respectively.

Not sure if this is a bug or something I do wrong somehow (or maybe it has to do with server configurations?). I can remove the double slashes with Twig, but it's annoying. Why does this happen, and is there anything I can do about it?

  • I just setup a test locally exactly as you described and I'm not getting a double // path separator. /Users/Brad/Dropbox/Sites/craft.dev/public/uploads/somefolder/somesubfolder/PT7-2.jpg – Brad Bell Oct 15 '15 at 21:07
  • 1
    @BradBell Thanks – it's a weird one. Probably something in my setup somehow. I'll do some debugging and will report back if I find the cause. – Mats Mikkel Rummelhoff Oct 15 '15 at 21:09
  • 1
    In our case, it was caused by a bad environment in general.php – Ryan Oct 26 '15 at 5:07
  • 1
    There is an environmentVariables array in general.php. We were actually generating double-slashes unintentionally. Something like "'assetsImagesUrl' => SITE_URL.'/uploads/images'", where SITE_URL already had a slash on the end. I only commented to save others from the same mistake - I don't think it's your issue. – Ryan Dec 1 '15 at 9:20
  • 1
    Yeah, that wasn't my issue, but it's definitely something that can easily happen. Thanks for clearing it up @Ryan! – Mats Mikkel Rummelhoff Dec 1 '15 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.