# Understanding .BaseURL and .RelPermalink

**URL:** <https://discourse.gohugo.io/t/understanding-baseurl-and-relpermalink/24988>\
**Category:** support\
**Created:** [April 24, 2020, 8:41am UTC](https://discourse.gohugo.io/t/understanding-baseurl-and-relpermalink/24988 "2020-04-24T08:41:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elby](https://avatars.discourse-cdn.com/v4/letter/e/9fc29f/32.png) [@Elby](https://discourse.gohugo.io/u/Elby)\
**Post date:** [April 24, 2020, 8:41am UTC](https://discourse.gohugo.io/t/understanding-baseurl-and-relpermalink/24988/1 "2020-04-24T08:41:45Z")

</div>

Hi,

I had understood that .RelPermalink was a relative link to .Site.BaseURL and that .Permalink was equivalent to {{ .Site.BaseURL }}{{ .RelPermalink }}.

This works fine fine with simple cases, but if I use complex BaseURL, I’m getting a different behavior.

Here is the configuration I set in config.toml:

```
baseURL = "http://example.org/some/directory/"

```

With the following layout:

```
{{ printf "baseURL : %s" .Site.BaseURL }}<br>
{{ printf "Permalink : %s" .Permalink }}<br>
{{ printf "RelPermalink : %s" .RelPermalink }}<br>

```

I get:

```
baseURL : http://example.org/some/directory/<br>
Permalink : http://example.org/some/directory/films/o_brother/<br>
RelPermalink : /some/directory/films/o_brother/<br>

```

I was expecting to get:

```
RelPermalink : films/o_brother/<br>

```

or:

```
RelPermalink : /films/o_brother/<br>

```

So I think I’m not supposed to use .Site.BaseURL and .RelPermalink together.  
What is .RelPermalink relative to ?

---

<div class="post-metadata">

**Author:** ![ju52](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ju52/32/6749_2.png) [@ju52](https://discourse.gohugo.io/u/ju52)\
**Post date:** [April 24, 2020, 5:33pm UTC](https://discourse.gohugo.io/t/understanding-baseurl-and-relpermalink/24988/2 "2020-04-24T17:33:18Z")

</div>

Alle local links don’t need the base URL. Using **.RelPermalink** generates smaller html pages. All browsers will generate complete URLs for requests.

I use **.Permalink** only in RSS feeds and in standalone files.

You can set the following in the head-section, if you need it.

`<head><base href={{.Site.BaseURL }} /></head>`

---

<div class="post-metadata">

**Author:** ![Elby](https://avatars.discourse-cdn.com/v4/letter/e/9fc29f/32.png) [@Elby](https://discourse.gohugo.io/u/Elby)\
**Post date:** [April 25, 2020, 7:10am UTC](https://discourse.gohugo.io/t/understanding-baseurl-and-relpermalink/24988/3 "2020-04-25T07:10:44Z")

</div>

I’m using a theme which uses a lot of absolute references,  
using href="{{ .Site.BaseURL }}{{ .RelPermalink }}" or href="{{ .Site.BaseURL }}{{ .URL }}".

These links get broken with complex BaseURL like in my example above :

```
{{ .Site.BaseURL }} = http://example.org/some/directory/
{{ .RelPermalink }} = /some/directory/films/o_brother/
--> href = http://example.org/some/directory//some/directory/films/o_brother/

```

It seems as you mention that href="{{ .RelPermalink }}" is enough, if I don’t define any base element in the head-section of the page.

This means that all links in the page, and thus in the content.md file, should be relative to the root of baseURL ( [http://example.org/](http://example.org/) ) and not relative to BaseURL itself, or to the root of the hugo directory.

If I want to define a link in a content.md file, I can use the relref shortcode to define a relative link to another .md file:

{{\< relref “/series/Dr\_House.md” \>}}  
–\> /some/directory/series/dr\_house/

But how should I define:

- a link to a another part of the site where there is no .md file, like the tag page  
[http://example.org/some/directory/tags/george\_clooney/](http://example.org/some/directory/tags/george_clooney/) ?

- an image located in hugo’s static files directory (/static/img/image.jpg) ?  
I didn’t see how to define relative links with the figure shortcode.

---

<div class="post-metadata">

**Author:** ![reorx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/reorx/32/16715_2.png) [@reorx](https://discourse.gohugo.io/u/reorx)\
**Post date:** [September 8, 2022, 3:40pm UTC](https://discourse.gohugo.io/t/understanding-baseurl-and-relpermalink/24988/4 "2022-09-08T15:40:56Z")

</div>

I find out a way to get the path relative to baseURL, i.e. `films/o_brother/` in your example:

```auto
strings.TrimPrefix (relURL "") .RelPermalink

```

I use this to make up the link to the archives of the current list page (section or term):

```auto
{{ printf "/%sarchives" (strings.TrimPrefix (relURL "") .RelPermalink) }}

```
