# absURL function strips path when using --baseURL flag

**URL:** <https://discourse.gohugo.io/t/absurl-function-strips-path-when-using-baseurl-flag/5925>\
**Category:** support\
**Created:** [March 25, 2017, 10:28am UTC](https://discourse.gohugo.io/t/absurl-function-strips-path-when-using-baseurl-flag/5925 "2017-03-25T10:28:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![36928495](https://avatars.discourse-cdn.com/v4/letter/3/e68b1a/32.png) [@36928495](https://discourse.gohugo.io/u/36928495)\
**Post date:** [March 25, 2017, 10:28am UTC](https://discourse.gohugo.io/t/absurl-function-strips-path-when-using-baseurl-flag/5925/1 "2017-03-25T10:28:36Z")

</div>

# Problem

The [absURL](https://gohugo.io/templates/functions/#absurl-relurl) function strips the path when using the [–baseURL](https://gohugo.io/overview/usage/) terminal flag, when not used inside the HTML ‘src’ or ‘href’ attribute.

## Use case

While in production for a new website, for the client to see, I simply dump a daily build in a sub-directory of my own website.

## Example

The list below, are the settings per file.

- **config.toml**  
`baseURL = "https://website1.com"`  
`canonifyurls = true`
- **\_index.md, with JSON frontmatter**  
`{"image": "/media/image/news/picture.jpg"}`
- **\_index.html**  
`<img src="{{ .Params.image }}" data-src="{{ .Params.image | absURL }}">`

Then using the following **terminal command** :  
`hugo --baseURL="https://website2.com/example/website1-com"`

## Result

`<img src="https://website2.com/example/website1-com/media/image/news/picture.jpg" data-src="https://website2.com/media/image/news/picture.jpg">`

Note the missing path _“example/website1-com/”_ in the “data-src” attribute.

## Question

Am I doing something wrong, or is this a bug?

## Software details

- **Hugo version**  
Hugo Static Site Generator v0.19 linux/amd64 BuildDate: 2017-02-27T13:35:54+01:00
- **OS**  
Fedora 25 64-bit

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [March 25, 2017, 1:22pm UTC](https://discourse.gohugo.io/t/absurl-function-strips-path-when-using-baseurl-flag/5925/2 "2017-03-25T13:22:02Z")

</div>

I understand this, but only after a really hard thinking:

So:

- The baseURL=https://website2.com/example/website1-com
- Image URL: “/media/image/news/picture.jpg”
- That image URL is relative to **the server/host**
- Given the above: absURL =\> [https://website2.com/media/image/news/picture.jpg](https://website2.com/media/image/news/picture.jpg)

So, if you remove the leading slash: “media/image/news/picture.jpg”

All should be good.

---

<div class="post-metadata">

**Author:** ![36928495](https://avatars.discourse-cdn.com/v4/letter/3/e68b1a/32.png) [@36928495](https://discourse.gohugo.io/u/36928495)\
**Post date:** [March 25, 2017, 1:48pm UTC](https://discourse.gohugo.io/t/absurl-function-strips-path-when-using-baseurl-flag/5925/3 "2017-03-25T13:48:09Z")

</div>

Yes, of course…  
Thank you very much for taking the time trying to understand my question and for writing an answer.

The solution is indeed easy:  
`<img src="{{ .Params.image }}" data-src="{{ slicestr .Params.image 1 | absURL }}">`

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [March 25, 2017, 2:19pm UTC](https://discourse.gohugo.io/t/absurl-function-strips-path-when-using-baseurl-flag/5925/4 "2017-03-25T14:19:53Z")

</div>

Well, that works, but I would say that fixing it in the source (page front matter) would be better. But up to you.

---

<div class="post-metadata">

**Author:** ![36928495](https://avatars.discourse-cdn.com/v4/letter/3/e68b1a/32.png) [@36928495](https://discourse.gohugo.io/u/36928495)\
**Post date:** [March 25, 2017, 6:45pm UTC](https://discourse.gohugo.io/t/absurl-function-strips-path-when-using-baseurl-flag/5925/5 "2017-03-25T18:45:06Z")

</div>

That would indeed be a better route to take. Thanks.

---

<div class="post-metadata">

**Author:** ![rdwatters](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rdwatters/32/2848_2.png) [@rdwatters](https://discourse.gohugo.io/u/rdwatters)\
**Post date:** [March 25, 2017, 10:43pm UTC](https://discourse.gohugo.io/t/absurl-function-strips-path-when-using-baseurl-flag/5925/6 "2017-03-25T22:43:42Z")

</div>

@36928495

If I may, and only if this is the type of site that’s going to grow large over a long period, I would take bep’s recommendation a step further and remove _all_ path-related info from the content so that the image is related strictly to the content itself and not any specific URL pattern or site architecture. I don’t know how you’re organizing the images overall, but you can use page variables like `.Section`, or `.URL` in conjunction with what you’re already doing…

It has the added benefit of less typing in the front matter (i.e. and therefore less room for human error), which speaks well to my laziness tendencies.

This is, of course, just a thought 😄
