Forward slashes in url

Hello guys:

I’m new to static site generators and html in general, so please bear with me here. Be patient :).

one of my index files has the following:

<link href="http://localhost:1313//index.xml" rel="alternate" type="application/rss+xml" title="A Hugo Blog" />

that results in the site index to have forward slashes.

localhost:1313//index.html

uglyUrls was specified in the config file, and even sitemap was disabled.

Removing the extra forward slash makes no difference, since the script automatically loads it.

I have the same problem with other themes.

How can I resolve the issue? Thanks.

Use {{.Site.BaseURL}} instead of http://localhost:1313//.

thanks Michael,

But what file should I modify ?

Is there a parameter I should include in the configuration file?

I also run the server with the baseUrl= but made no difference.

Carlos,
You need to give us more information. Are you using a theme? How are you calling hugo (which flags)?

hello Steve.

I was going to reply earlier but had to figure out a problem (headache) with git first. :slight_smile: I had been using two machines to push and pull and I made a few mistakes along the way.

The theme I 'm using is twentyfourteen, but I also had a problem while loading hyde-x, and others. But hyde for example runs without a problem.

I normally run it, with the hugo server --theme=<themename> --buildDrafts, or I specify the theme in the config.yml file or the config.toml

Michael’s suggestion seems to make sense, but my knowledge is limited to implement it correctly. Is it case {{.Site.BaseURL}} ?

I couldn’t upload an image because of privileges so here is the site https://nonumeros.github.io

I have the same problem (hugo v0.13). I’m just starting up with hugo and build the site from the site directory as follows.

hugo -t tinyce

my config.toml

baseurl = "http://test.me/"
languageCode = "en-us"
title = “Hugo | Test”

I have tried canonifyurls = true and tried removing ending slash of baseurl with no success.

In the output some urls look as follows

http://test.me//css/application.css

http://test.me//images/profile.jpg

If you’re getting two slashes, it’s likely that your config file has a slash at the end of the baseurl and that your layout is also putting a slash at the beginning. In that case, just remove the slash at the end of baseurl.

Just wondering if you’ve found solution for your problem with the double slashes? I’m also using the twentyfourteen theme without any modification (so far)

I’ve just started with Hugo - running the hugo server locally works fine as I guess the hugo server is a bit forgiving with the double slash in the url’s for the stylesheets etc. S3 is not so forgiving as the local server (travel.jamesprenderga.st).

hugo config shows baseurl without the trailing slash and the theme templates don’t have an extra slash in them either ie:

themes/twentyfourteen/layouts/partials/header.html

...
<link rel='stylesheet' id='twentyfourteen-style-css' href='{{ .Site.BaseUrl }}/css/style.css' type='text/css' media='all' />
...

I would guess that the theme is somehow modifying the Site.BaseUrl property - just haven’t figured out where or how yet

If this gives double slashes, why not try to remove one slash from one of them?

I’m experiencing the same double slash problem, which generates a broken site when hosted on S3.

Relevant config.yaml settings:

baseurl: http://new.alestic.com
theme: purehugo

The theme has this:

<link rel="stylesheet" href="{{ .Site.BaseUrl }}/css/all.min.css">

which gets written incorrectly as this (note double slash after host):

    <link rel="stylesheet" href="http://new.alestic.com//css/all.min.css">

Running hugo version:

Hugo Static Site Generator v0.13 BuildDate: 2015-02-21T20:02:30-08:00

This commit seems to imply that the baseurl should end in a trailing slash: https://github.com/spf13/hugo/commit/9d80ecb4d8efa1a45f649d8b75d7e2c946c09070

Does that mean that the themes need to be updated to not inject a leading slash?

Until I know the right direction to go, I’m temporarily getting around the issue by syncing the site to / and // on S3.

Hi guys,

I had the same problem, but then removed the slash after the BaseURL and it’s fine. Like this:

<link rel="stylesheet" href="{{ .Site.BaseUrl }}css/all.min.css">

observe, no slash after {{ .Site.BaseUrl }}.

That commit implies that trailng slashes shouldn’t be removed, but I will check this later.

See

I have committed a fix for the above. Looks like this was introduced in a commit on the 18th of February.

yeah, I’m doing that for the time being. I see it’s fixed in the latest commit, but I’m using wercker to build and deploy and that’s currently using the 0.13 build. Will revert once the 0.14 build is released.

Thanks!

I have added two new template funcs, absURL and relURL.

They are documented here https://github.com/spf13/hugo/blob/master/docs/content/templates/functions.md

When Hugo 0.14 is out in the open, I would say that these should be the recommended way to link in static resources like CSS, JS etc. It’s much easier to handle missing or too many trailing slashes etc. in a Go func, compared to a template.

1 Like

Hi, guys!

I’m sorry for bother you all. I’m new to Hugo and… Well, you know. I’m having issues with the trailing slash.

In the end, will {{ .Site.BaseUrl }} have or not a trailing slash? (I hate it, I hate it, I hate it…)

Thank you!

Test it and see.

Thank you

I read a lot about it and I thought it was a regression bug. The docs shows a sample config with a /:

baseurl = "http://yoursite.example.com/"

I thought that if the sample shows a /, it’s because it isn’t add by default. I’m sorry.

I gonna try to use only root relative URLs, then, and to avoid {{ .Site.BaseURL }}.

Have a good night.

Thank you.

1 Like