# How not to specify URL site?

**URL:** <https://discourse.gohugo.io/t/how-not-to-specify-url-site/5691>\
**Category:** support\
**Created:** [March 4, 2017, 7:53pm UTC](https://discourse.gohugo.io/t/how-not-to-specify-url-site/5691 "2017-03-04T19:53:46Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![igramnet](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/igramnet/32/2715_2.png) [@igramnet](https://discourse.gohugo.io/u/igramnet)\
**Post date:** [March 4, 2017, 7:53pm UTC](https://discourse.gohugo.io/t/how-not-to-specify-url-site/5691/1 "2017-03-04T19:53:46Z")

</div>

Good afternoon. Can I as baseURL specify the value “/”? I it is important to make sure that the site was not attached to a domain. How to do it?

---

<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 4, 2017, 8:49pm UTC](https://discourse.gohugo.io/t/how-not-to-specify-url-site/5691/3 "2017-03-04T20:49:26Z")

</div>

> [@igramnet](#):
>
> Can I as baseURL specify the value “/”?

In your site’s `config.toml` and `config.yml`, respectively:

```toml
baseurl = "/"

```

Or…

```yaml
baseurl: "/"

```

I believe that the default value when running `hugo server` is actually the full `localhost:1313/` with the closing `/`, so this _might_ (not sure of your end goal) help keep consistency between your dev and prod environments. That said, make sure you look into [the `relURL` and `absURL` functions](https://gohugo.io/templates/functions#absurl-relurl), since I’m starting to think this is a better practice overall for your templating, especially if you’re creating themes 😄

---

<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 4, 2017, 9:11pm UTC](https://discourse.gohugo.io/t/how-not-to-specify-url-site/5691/4 "2017-03-04T21:11:24Z")

</div>

“/” is not a valid `baseURL`. It _may work_, but may have undefined behavior in some scenarios (the `relativeURL` may not be happy, `relURL` / `absURL` may not be happy).

If you want relative URLs then use relative URLs in your templates.

---

<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 4, 2017, 10:30pm UTC](https://discourse.gohugo.io/t/how-not-to-specify-url-site/5691/5 "2017-03-04T22:30:51Z")

</div>

> [@bep](#):
>
> “/” is not a valid baseURL. It may work, but may have undefined behavior in some scenarios (the relativeURL may not be happy, relURL / absURL may not be happy).

@bep

Then I want to make this clearer in the docs.

**Here’s why, for anyone interested:**

In a template for a site with a configured `baseurl = "http://mysite.com"`, running locally the following will work…

```auto
<link rel="stylesheet" href="{{.Site.BaseURL}}css/style.css">

```

Because, at least from what I remember a couple versions ago, the local server includes the trailing slash, as follows:

```auto
<link rel="stylesheet" href="http://localhost:1313/css/style.css">

```

However, using the example `http://mysite.com` (or even leaving the `baseurl` field empty [`baseurl = ""`]) in the `config` would create the following at build:

```auto
<link rel="stylesheet" href="http://mysite.comcss/style.css">

```

Which breaks for obvious reasons. As I mentioned already, using `relURL` and `absURL` functions are a best practice, especially in the context of themes, _but_ I’d like to make this _ **clearer** _ in the docs.

I don’t feel like I’ve seen this a lot _lately_, but there was certainly confusion about it in the past and in my own experience starting Hugo…if my memory serves.

---

<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 4, 2017, 11:19pm UTC](https://discourse.gohugo.io/t/how-not-to-specify-url-site/5691/6 "2017-03-04T23:19:52Z")

</div>

> [@rdwatters](#):
>
> \<link rel=“stylesheet” href=“{{.Site.BaseURL}}css/style.css”\>

For the docs, never use that manual concatenation, because it can never handle the subtle differences in `baseURL` properly.

And we

- Cannot add any more magic to “fix” `baseURL` because of the above example
- We cannot add any validation of `baseURL` because of the many variants in the wild.

So:

Use:

- `relURL` or `relLangURL` for relative URLs
- `absURL` or `absLangURL` for absolute URLS

If you use the `relativeURLs` setting, you basically have to use all relative URLs in the templates.

You may try to use “/” or some other non-URL value in `baseURL`, but you are basically on your own, so do not file any issue on the issue tracker if “something doesn1’t work”.

---

<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 5, 2017, 12:12am UTC](https://discourse.gohugo.io/t/how-not-to-specify-url-site/5691/7 "2017-03-05T00:12:51Z")

</div>

**[EDIT]: Forgot about the warning in the console re: menus and BaseURL…hmmm…disregard.**

> [@bep](#):
>
> You may try to use “/” or some other non-URL value in baseURL, but you are basically on your own, so do not file any issue on the issue tracker if “something doesn1’t work”.

I think that’s all I needed…this should be clarified for users, so I’m thinking that really the _only_ purpose, at least moving forward, for the `baseurl` field in the config is to define the _full_ base URL of your website for deployment purposes…and that referring to it specifically in templates (or doing something similar to `{{$base := .Site.BaseURL}}` is more or less a bad idea…?

---

<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 5, 2017, 8:39am UTC](https://discourse.gohugo.io/t/how-not-to-specify-url-site/5691/8 "2017-03-05T08:39:03Z")

</div>

1. I think an `URL`, if not having some kind of relative context, is always absolute, see [https://en.wikipedia.org/wiki/Uniform\_Resource\_Locator](https://en.wikipedia.org/wiki/Uniform_Resource_Locator)
2. There could be use cases for handling the `BaseURL` directly, but not for creating references to `CSS´ and other resources that need an absolute URL.

---

<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 5, 2017, 9:44am UTC](https://discourse.gohugo.io/t/how-not-to-specify-url-site/5691/9 "2017-03-05T09:44:04Z")

</div>

> [@bep](#):
>
> There could be use cases for handling the BaseURL directly

The only thing that’s springing to mind for me is

```auto
<link rel="dns-prefetch" href="{{ .Site.BaseURL }}">
 <link rel="preconnect" href="{{ .Site.BaseURL }}">

```

But then maybe not if the end user isn’t putting the Hugo site at the root. I’m sure there are others, but it is almost 4am here in Chicago, so I’m not at 100% 😄

---

<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 5, 2017, 9:47am UTC](https://discourse.gohugo.io/t/how-not-to-specify-url-site/5691/10 "2017-03-05T09:47:26Z")

</div>

> [@rdwatters](#):
>
> \<link rel=“dns-prefetch” href=“{{ .Site.BaseURL }}”\>

```auto
<link rel="dns-prefetch" href="{{ "/" | absURL }}">
<link rel="dns-prefetch" href="{{ "/" | relURL }}">

```

---

<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 5, 2017, 9:56am UTC](https://discourse.gohugo.io/t/how-not-to-specify-url-site/5691/11 "2017-03-05T09:56:21Z")

</div>

> [@bep](#):
>
> \<link rel=“dns-prefetch” href=“{{ “/” | relURL }}”\>

I don’t have a Wikipedia article on this, so I hope you regard the [WC3](https://w3c.github.io/resource-hints/#dfn-dns-prefetch) as an equally scholarly resource:

> The dns-prefetch link relation type is used to indicate an _ **origin** _ that will be used to fetch required resources, and that the user agent should resolve as early as possible.

What am I missing if I’m thinking that your `relURL` example doesn’t fit here?

---

<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 5, 2017, 10:04am UTC](https://discourse.gohugo.io/t/how-not-to-specify-url-site/5691/12 "2017-03-05T10:04:28Z")

</div>

You are right … I didn’t know what dns-prefetch was …
