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

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

<p><em>Restrict uploads to a single folder (true)</em><br>
<em>Upload location: [source:Images] <code>somefolder/somesubfolder</code></em></p>

<p>Calling <code>{{ asset.getUrl() }}</code> on an asset from this field returns the following URL:</p>

<p><strong><code>/uploads/images/somefolder//somesubfolder/image.jpg</code></strong></p>

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

<p>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 (<code>getUrl(false)</code>).</p>

<p><em>If the source configuration should prove relevant somehow, here's the setup:</em></p>

<p>I've got an asset source (local folder) called <code>Images</code> configured like this:  </p>

<p><em>File System Path:</em> <code>{imagePath}/</code><br>
<em>URL:</em> <code>{imageUri}/</code></p>

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

<p>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?</p>

CC BY-SA 3.0
2015-10-15T21:07:02.900Z
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
CC BY-SA 3.0
2015-10-15T21:09:45.593Z
@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
CC BY-SA 3.0
2015-10-26T04:55:48.080Z
We are getting the same problem in Craft 2.4.2693. It's causing issues with Facebook Open Graph.
Ryan
CC BY-SA 3.0
2015-10-26T05:07:06.700Z
In our case, it was caused by a bad environment in general.php
Ryan
CC BY-SA 3.0
2015-11-26T21:52:43.510Z
@Ryan – I never actually solved this. Can you elaborate? What do you mean by "bad environment"?
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2015-12-01T09:20:05.357Z
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
CC BY-SA 3.0
2015-12-01T10:36:14.323Z
Yeah, that wasn't my issue, but it's definitely something that can easily happen. Thanks for clearing it up @Ryan!
Mats Mikkel Rummelhoff
<templating><assets><content>
asset.getUrl() outputs double slashes
# asset.getUrl() outputs double slashes

(Asked by: username_0 on 2015-10-15)

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:

**`/uploads/images/somefolder//somesubfolder/image.jpg`**

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?

**Tags:** templating, assets, content
> **Comments:**
> **username_1**: 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`  
> **username_0**: @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.  
> **username_2**: We are getting the same problem in Craft 2.4.2693. It's causing issues with Facebook Open Graph.  
> **username_2**: In our case, it was caused by a bad environment in general.php  
> **username_0**: @Ryan – I never actually solved this. Can you elaborate? What do you mean by "bad environment"?  
> **username_2**: 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.  
> **username_0**: Yeah, that wasn't my issue, but it's definitely something that can easily happen. Thanks for clearing it up @Ryan!  

---

## 0 answers

