# Issue when baseurl have subdirectory

**URL:** <https://discourse.gohugo.io/t/issue-when-baseurl-have-subdirectory/4088>\
**Category:** support\
**Created:** [September 12, 2016, 9:51pm UTC](https://discourse.gohugo.io/t/issue-when-baseurl-have-subdirectory/4088 "2016-09-12T21:51:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Protik\_Das](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@Protik\_Das](https://discourse.gohugo.io/u/Protik_Das)\
**Post date:** [September 12, 2016, 9:51pm UTC](https://discourse.gohugo.io/t/issue-when-baseurl-have-subdirectory/4088/1 "2016-09-12T21:51:19Z")

</div>

Hi all,

My `baseurl` is something like: [some.uni.edu/~pdas/](http://some.uni.edu/~pdas/) . It seems when the `baseurl` have subdirectory, then the internal links are not rendered correctly. When the site is created using hugo command then the `/~pdas` part is omitted by all the internal URLs. As a result the internal links along with the images are not rendered correctly.

Is this a bug related to Hugo or it have something to do with the theme? I am using [academic](https://github.com/gcushen/hugo-academic).

For example please see this post: [http://www.ece.ucr.edu/~pdas/post/benchmarking-vasp-in-xsede/](http://www.ece.ucr.edu/~pdas/post/benchmarking-vasp-in-xsede/). Here the image URL are missing the `~pdas` part of the URL. As a result the post is not showing the images correctly. My version is: `Hugo Static Site Generator v0.16 BuildDate: 2016-06-06T05:33:33-07:00`.

---

<div class="post-metadata">

**Author:** ![michael\_henderson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/michael_henderson/32/10490_2.png) [@michael\_henderson](https://discourse.gohugo.io/u/michael_henderson)\
**Post date:** [September 13, 2016, 2:16am UTC](https://discourse.gohugo.io/t/issue-when-baseurl-have-subdirectory/4088/2 "2016-09-13T02:16:49Z")

</div>

Can you give us the command that you use to build your site, please?

---

<div class="post-metadata">

**Author:** ![Protik\_Das](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@Protik\_Das](https://discourse.gohugo.io/u/Protik_Das)\
**Post date:** [September 13, 2016, 2:20am UTC](https://discourse.gohugo.io/t/issue-when-baseurl-have-subdirectory/4088/3 "2016-09-13T02:20:07Z")

</div>

I tried both `hugo` and `hugo --theme=academic`. The output is same.

---

<div class="post-metadata">

**Author:** ![Protik\_Das](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@Protik\_Das](https://discourse.gohugo.io/u/Protik_Das)\
**Post date:** [September 13, 2016, 7:38pm UTC](https://discourse.gohugo.io/t/issue-when-baseurl-have-subdirectory/4088/4 "2016-09-13T19:38:44Z")

</div>

It turned out to be a Hugo bug for no rooted websites… Will wait for it to be resolved in next version.

In the meantime I have solved the issue by setting both `relativeURLS` and `canonifyurls` to `true`.

---

<div class="post-metadata">

**Author:** ![pooh22](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@pooh22](https://discourse.gohugo.io/u/pooh22)\
**Post date:** [September 20, 2016, 1:20pm UTC](https://discourse.gohugo.io/t/issue-when-baseurl-have-subdirectory/4088/5 "2016-09-20T13:20:39Z")

</div>

This is very similar to what I experience. I’m testing some hugo sites using a deploy script which substitutes the baseurl in the config.toml to have it sit under something like [http://test.example.org/SITE/](http://test.example.org/SITE/) and in production it runs (e.g.) under [http://site.org/](http://site.org/)

I’m using the HugoMDL theme and what breaks is at least the cardthumbimage and cardheaderimage, which are by default under /images/cardthumbimage.png or something similar.  
If this would be rendered as baseurl+/images/cardthumbimage.png it would turn out ok, but as it is, it’s always /images/cardthumbimage.png

Is this the same bug?

---

<div class="post-metadata">

**Author:** ![ominty](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ominty/32/2716_2.png) [@ominty](https://discourse.gohugo.io/u/ominty)\
**Post date:** [February 3, 2017, 6:30am UTC](https://discourse.gohugo.io/t/issue-when-baseurl-have-subdirectory/4088/6 "2017-02-03T06:30:12Z")

</div>

As far as I understand you need a truely portable Website.  
To test this you may start it from the local file system/public folder without the use of hugo server. If successful it should work anywhere, also in your server subdirectory.

To get this see this discussion: [https://discuss.gohugo.io/t/could-not-get-relativeurls-to-work-with-site-baseurl/5301/9](https://discuss.gohugo.io/t/could-not-get-relativeurls-to-work-with-site-baseurl/5301/9)  
But be prepared to do changes in the theme as explained there.

---

<div class="post-metadata">

**Author:** ![kpietak](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kpietak/32/4797_2.png) [@kpietak](https://discourse.gohugo.io/u/kpietak)\
**Post date:** [January 8, 2018, 8:05pm UTC](https://discourse.gohugo.io/t/issue-when-baseurl-have-subdirectory/4088/7 "2018-01-08T20:05:36Z")

</div>

@Protik_Das any news about the fix? (you wrote that the issue will be in a next version).

I’m using 0.32.2 version of hugo (with ananke theme) and the problem still exists. The option `canonifyURLs` solves the problem, but as it is not a default (and suggested) setting, I’m wondering if something related to this issue is still happaning.

---

<div class="post-metadata">

**Author:** ![honghe](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/honghe/32/5371_2.png) [@honghe](https://discourse.gohugo.io/u/honghe)\
**Post date:** [March 1, 2018, 1:30pm UTC](https://discourse.gohugo.io/t/issue-when-baseurl-have-subdirectory/4088/8 "2018-03-01T13:30:28Z")

</div>

Use the following config to solve this problem.

```auto
RelativeURLs=true
CanonifyURLs=true

```

> [@CanonifyURLs & RelativeURLs interaction](https://discourse.gohugo.io/t/canonifyurls-relativeurls-interaction/5448):
>
> PSA: CanonifyURLs and RelativeURLs interact with each other, and in particular if you use RelativeURLs=true, you may want to use CanonifyURLs=true also. If both are true, CanonifyURLs will not actually canonify all your relative urls… It will however change the way the internal RelURL and adding context root to urls happens… I wish I had known/seen this earlier because it works around some of the main problems I’d written about in my comments in the below linked topics. I didn’t see this in…

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [February 27, 2020, 2:15pm UTC](https://discourse.gohugo.io/t/issue-when-baseurl-have-subdirectory/4088/9 "2020-02-27T14:15:03Z")

</div>


