# Link to static file

**URL:** <https://discourse.gohugo.io/t/link-to-static-file/78>\
**Category:** support\
**Created:** [September 21, 2014, 5:48pm UTC](https://discourse.gohugo.io/t/link-to-static-file/78 "2014-09-21T17:48:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fedelibre](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/fedelibre/32/50_2.png) [@fedelibre](https://discourse.gohugo.io/u/fedelibre)\
**Post date:** [September 21, 2014, 5:48pm UTC](https://discourse.gohugo.io/t/link-to-static-file/78/1 "2014-09-21T17:48:53Z")

</div>

How can I link to a file saved in static/?  
The following generates the right file path but hugo server returns a 404 error:

```
[here's my link](/static/folder/file.txt)
```

---

<div class="post-metadata">

**Author:** ![oscar\_b](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/oscar_b/32/40_2.png) [@oscar\_b](https://discourse.gohugo.io/u/oscar_b)\
**Post date:** [September 21, 2014, 8:14pm UTC](https://discourse.gohugo.io/t/link-to-static-file/78/2 "2014-09-21T20:14:01Z")

</div>

Try putting the file in static/static in that case.

---

<div class="post-metadata">

**Author:** ![spf13](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/spf13/32/37_2.png) [@spf13](https://discourse.gohugo.io/u/spf13)\
**Post date:** [September 21, 2014, 8:22pm UTC](https://discourse.gohugo.io/t/link-to-static-file/78/3 "2014-09-21T20:22:51Z")

</div>

It would just be /folder/file.txt

---

<div class="post-metadata">

**Author:** ![fedelibre](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/fedelibre/32/50_2.png) [@fedelibre](https://discourse.gohugo.io/u/fedelibre)\
**Post date:** [September 21, 2014, 8:42pm UTC](https://discourse.gohugo.io/t/link-to-static-file/78/4 "2014-09-21T20:42:39Z")

</div>

> [@spf13](#):
>
> It would just be /folder/file.txt

Sure, I should have tried that also, but my unix-minded (filesystem) approach was using the full path or the relative path without /  
Thanks

---

<div class="post-metadata">

**Author:** ![jorin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jorin/32/4172_2.png) [@jorin](https://discourse.gohugo.io/u/jorin)\
**Post date:** [October 1, 2014, 2:24pm UTC](https://discourse.gohugo.io/t/link-to-static-file/78/5 "2014-10-01T14:24:27Z")

</div>

It’s always better to have absolute links in case you host the side at a relative domain (like _/blog_).  
You can create a shortcode (at `layouts/shortcodes/link.html`) to generate absolute links:

```
<a href="{{ .Page.Site.BaseUrl }}/{{ .Get 0 }}"/>
    {{ .Inner }}
</a>

```

And use it in the markdown like this:

```
{{% link <url> %}}Some Text{{% /link %}}

```

You can pass more options to the shortcode if you want to be more specific.  
Also useful to have something similar for `<img>`.

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [April 25, 2021, 2:46am UTC](https://discourse.gohugo.io/t/link-to-static-file/78/6 "2021-04-25T02:46:19Z")

</div>

A post was split to a new topic: [Is this the right static dir?](https://discourse.gohugo.io/t/is-this-the-right-static-dir/32517)

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [April 25, 2021, 2:46am UTC](https://discourse.gohugo.io/t/link-to-static-file/78/7 "2021-04-25T02:46:49Z")

</div>


