# baseURL = mysite.com/test causes wrong menu links like mysite.com/test/test/about

**URL:** https://discourse.gohugo.io/t/baseurl-mysite-com-test-causes-wrong-menu-links-like-mysite-com-test-test-about/3209
**Category:** support
**Created:** [April 26, 2016, 2:11pm UTC](https://discourse.gohugo.io/t/baseurl-mysite-com-test-causes-wrong-menu-links-like-mysite-com-test-test-about/3209 "2016-04-26T14:11:16Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![christophberger](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/christophberger/32/1537_2.png) [@christophberger](https://discourse.gohugo.io/u/christophberger)
#### Post date: [April 26, 2016, 2:11pm UTC](https://discourse.gohugo.io/t/baseurl-mysite-com-test-causes-wrong-menu-links-like-mysite-com-test-test-about/3209/1 "2016-04-26T14:11:16Z")

</div>

Hi,

I am a Hugo newbie, so apologies if the cause of the below is obvious to you, but I cannot seem to make a baseURL work if it contains more than just the domain, e.g. `https://mysite.com/test`. For some reason, the links to content contain the “test” dir twice, like e.g. `https://mysite.com/test/test/about/`.

I already searched through the docs and the forum but without a result.

What I have in config.toml:

```
baseurl = "https://mysite.com/test"

[[menu.main]]
		name= "About"
		url = "/about/"

```

All other relevant settings should be pretty much default. (E.g. I did not set canonifyurl etc.)  
And in `content/` there is an `about.md` file. Nothing unusual so far.

Now if I run Hugo (v0.15) to generate the site into $PUBLIC\_WWW/test…

```
hugo -d $HOME/html/test

```

…and point a browser to `https://mysite.com/test`, the home page loads fine but the link to the about page looks like this:

```
https://mysite.com/test/test/about/

```

The theme I use is Hype-X.

Did I overlook something obvious? How can I make this setup work?

Thanks,  
Christoph

---

<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: [April 26, 2016, 4:09pm UTC](https://discourse.gohugo.io/t/baseurl-mysite-com-test-causes-wrong-menu-links-like-mysite-com-test-test-about/3209/2 "2016-04-26T16:09:08Z")

</div>

> [@christophberger](#):
>
> Did I overlook something obvious? How can I make this setup work?

This looks strange; you can try to add server-relative URL in the menu config “/test/about”, but other than that I would suggest you try the Hugo source version. We should really, really release a new version soon. A lot have happened since 0.15.

---

<div class="post-metadata">

### Author: ![christophberger](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/christophberger/32/1537_2.png) [@christophberger](https://discourse.gohugo.io/u/christophberger)
#### Post date: [April 26, 2016, 9:45pm UTC](https://discourse.gohugo.io/t/baseurl-mysite-com-test-causes-wrong-menu-links-like-mysite-com-test-test-about/3209/3 "2016-04-26T21:45:10Z")

</div>

> [@bep](#):
>
> I would suggest you try the Hugo source version.

Thanks for this suggestion, it made indeed a difference. Now the menus (about etc.) work fine, but the links that worked previously (like CSS links etc.) now have no `test/` part at all, just as if they ignore the baseURL. (All those links, as far as I checked them, are of the form `{{ "/css/poole.css" | absURL }}`. Strangely enough, the menu links use the same format: `{{ .URL | absURL }}`. (Note this template code is from the Hyde-X templates - I assume this theme has been used and tested since quite a while now.)

This is what I observe with v0.16-DEV:

Menu links work now (from layouts/partial/sidebar.html). Their template uses this format:

```
{{ .URL | absURL }}

```

The “Home” link doesn’t work (also located in sidebar.html). The template format is similar:

```
{ "/" | absURL }}

```

CSS links fail, too (in head.html) - same template format:

```
{{ "/css/poole.css" | absURL }}

```

When I remove the leading slashes, the Home link and the CSS links start working:

```
{{ "" | absURL }}

```

and

```
{{ "css/poole.css" | absURL }}

```

respectively.

I also noticed that image tags from the Markdown source of a blog post do not seem to get processed properly. Of the following image tags, only the last one works:

```
![image](gopher.png "Gopher") <-- fails

![image](post/gopher.png "Gopher") <-- fails

![image](/post/gopher.png "Gopher") <-- fails

![image](test/post/gopher.png "Gopher") <-- fails

![image](/test/post/gopher.png "Gopher") <-- works

```

Because of the baseURL setting (“`https://mysite.com/test`”) I should not need to use “`/test/`” at all in the image path.

All of this is quite confusing. I only want to live-test on a real server without exposing the site to the public yet. With local `hugo server` (which ignores the baseURL) everything works like a charm.

Is there any other approach for testing a site from within a subdirectory, without breaking half of the links?

Thanks,  
Christoph

---

<div class="post-metadata">

### Author: ![christophberger](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/christophberger/32/1537_2.png) [@christophberger](https://discourse.gohugo.io/u/christophberger)
#### Post date: [April 27, 2016, 9:43am UTC](https://discourse.gohugo.io/t/baseurl-mysite-com-test-causes-wrong-menu-links-like-mysite-com-test-test-about/3209/4 "2016-04-27T09:43:11Z")

</div>

I finally found a workaround to the issue:

**Use a subdomain.**

It seems as long as the baseURL does **not** point to any subdirectory, everything works well.

---

<div class="post-metadata">

### Author: ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)
#### Post date: [April 27, 2016, 1:14pm UTC](https://discourse.gohugo.io/t/baseurl-mysite-com-test-causes-wrong-menu-links-like-mysite-com-test-test-about/3209/5 "2016-04-27T13:14:16Z")

</div>

The `absURL` function only converts _relative paths_. If you pass in a string that starts with `http` or `/`, `absURL` doesn’t prepend the `baseURL`. We should update the docs to explain this behavior.

The image tags in your Markdown are a bit of a special case. The `blackfriday` package renders that content without Hugo processing the URLs/paths. Hugo’s `baseURL` capabilities come into play only in the layouts. If you want to use `absURL` from within your content, you’ll need to create a shortcode for that. For example:

```auto
![image]({{< absurl post/gopher.png >}} "Gopher")

```

---

<div class="post-metadata">

### Author: ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)
#### Post date: [April 27, 2016, 1:53pm UTC](https://discourse.gohugo.io/t/baseurl-mysite-com-test-causes-wrong-menu-links-like-mysite-com-test-test-about/3209/6 "2016-04-27T13:53:14Z")

</div>

After looking at the code, I need to correct my last post.

> [@moorereason](#):
>
> If you pass in a string that starts with `http` or `/`, `absURL` doesn’t prepend the `baseURL`.

That should be: If you pass in a string that starts with `http` or `//`, `absURL` doesn’t prepend the `baseURL`. Note the double slash.

`absURL` does prepend the `baseURL` if you pass in a path starting with `/`, but it **removes** any path in the `baseURL` before doing so. So, instead of prepending `https://mysite.com/test`, it prepends `https://mysite.com`.

I don’t know where all this function is being used inside of Hugo, but it is confusing.

---

<div class="post-metadata">

### Author: ![christophberger](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/christophberger/32/1537_2.png) [@christophberger](https://discourse.gohugo.io/u/christophberger)
#### Post date: [April 27, 2016, 1:56pm UTC](https://discourse.gohugo.io/t/baseurl-mysite-com-test-causes-wrong-menu-links-like-mysite-com-test-test-about/3209/7 "2016-04-27T13:56:16Z")

</div>

> [@moorereason](#):
>
> If you pass in a string that starts with http or /, absURL doesn’t prepend the baseURL.

In my tests the baseURL always got prepended, just not always with the correct result. If absURL ignores strings that start with `/`, then there must be some other mechanism that also builds a full URL from the snippets in the layouts (and fails when the baseURL points to a subdir).

Anyway, after switching from subdir to subdomain, I have not seen these problems anymore.

Thanks,  
Christoph

---

<div class="post-metadata">

### Author: ![phi](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@phi](https://discourse.gohugo.io/u/phi)
#### Post date: [April 27, 2016, 2:02pm UTC](https://discourse.gohugo.io/t/baseurl-mysite-com-test-causes-wrong-menu-links-like-mysite-com-test-test-about/3209/8 "2016-04-27T14:02:36Z")

</div>

Don’t know, but maybe the absURL is not used in your layout, there is another way to get a full path:

```
<link href="{{ .Site.BaseURL }}favicon.png" rel="shortcut icon">

```

These different ways of creating a full path may be a reason that it is working sometimes…

---

<div class="post-metadata">

### Author: ![christophberger](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/christophberger/32/1537_2.png) [@christophberger](https://discourse.gohugo.io/u/christophberger)
#### Post date: [April 27, 2016, 2:50pm UTC](https://discourse.gohugo.io/t/baseurl-mysite-com-test-causes-wrong-menu-links-like-mysite-com-test-test-about/3209/9 "2016-04-27T14:50:49Z")

</div>

Thanks for the hint, I’ll keep this in mind in case I build my own layout. Right now I use Hype-X which works fine so far. I only tweak the visual appearance a bit, that’s enough for me until I get more familar with Hugo theming.

---

<div class="post-metadata">

### Author: ![appernetic](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/appernetic/32/1464_2.png) [@appernetic](https://discourse.gohugo.io/u/appernetic)
#### Post date: [October 31, 2016, 11:34am UTC](https://discourse.gohugo.io/t/baseurl-mysite-com-test-causes-wrong-menu-links-like-mysite-com-test-test-about/3209/10 "2016-10-31T11:34:08Z")

</div>

I found this old topic when I tried to solve an issue where absURL suddenly was not working after upgrading Hugo from version 0.15 to 0.17. In v0.15 you could use / in absURL like this: `href="{{ "/css/highlight/" | absURL }}default.css"` but now in v0.17 I had to remove the first /: `href="{{ "css/highlight/" | absURL }}default.css"`. to make it work.

I have not seen any documentation that it’s behaviour has changed.

Anyway good to find a solution!
