Removing the folder name from the article link

My folder construction is as follows:

image

This is the content of what-is-a-webmaster.md file:

---
title: What is a Webmaster?
slug: what-webmaster
---

Although I set the slug value to what-webmaster, the link to my article is as follows:

https://example.com/webmaster/what-webmaster/

The reason why my article is in the webmaster folder is to create a layout of my own, but it adds the folder name /webmaster/ to the link of my article without my request.

How can I remove the /webmaster/ folder from my article link?

If you want to do the same thing for all pages in the webmaster folder, set permalinks in the site configuration.

1 Like
[permalinks]

post = "/:slug/"

I tried that but it didn’t work.

[permalinks]
webmaster = "/:slug/"

This works fine.

1 Like

If I want to do this to all folders, what should I put in the word webmaster?

[permalinks]
webmaster = "/:slug/"
seo = "/:slug/"
books = "/:slug/"
1 Like

The permalinks setting applies to regular pages, not section pages. To set the URL for section pages, you will need to set the url in front matter.

There’s an open issue about this:
https://github.com/gohugoio/hugo/issues/8523

1 Like
[permalinks]

[permalinks.page]
posts = "/:slug/"

[permalinks.section]
posts = "/:slug/"

This is how it is used in the link you mentioned, but when I start hugo, I get an error like this:

panic: runtime error: slice bounds out of range [1:0]
goroutine 1 [running]:
github.com/gohugoio/hugo/resources/page.PermalinkExpander.validate({0xc00030a4b0?, 0x0?, 0xc00013fda0?}, {0x0?, 0x0?})
        /root/project/hugo/resources/page/permalinks.go:183 +0x23b
github.com/gohugoio/hugo/resources/page.PermalinkExpander.parse({0xc00030a4b0?, 0x0?, 0xc00013fda0?}, 0x8?)
        /root/project/hugo/resources/page/permalinks.go:126 +0x136
github.com/gohugoio/hugo/resources/page.NewPermalinkExpander(0xc00013fda0)
        /root/project/hugo/resources/page/permalinks.go:95 +0x7a5
github.com/gohugoio/hugo/resources.NewSpec(0xc00013fda0, 0xc00013fe30, {0x28913e0, 0xc00011ea98}, {0x28b0110, 0xc0001a9c20}, {0x2891400?, 0xc00000a9e0}, 0xc000119cc0, {0xc0001b2000, ...}, ...)
        /root/project/hugo/resources/resource_spec.go:76 +0x205
github.com/gohugoio/hugo/deps.New({{0x28b0110, 0xc0001a9c20}, 0xc00020e7e0, 0xc0006c8f00, {0x0, 0x0}, {0x28ad5e0, 0xc0004a1090}, {0xc000716000, 0x22, ...}, ...})
        /root/project/hugo/deps/deps.go:289 +0x705
github.com/gohugoio/hugo/hugolib.configLoader.applyDeps({{0x0, 0x0}, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, ...}}, ...)
        /root/project/hugo/hugolib/hugo_sites.go:519 +0x31e
github.com/gohugoio/hugo/hugolib.newHugoSites({{0x28b0110, 0xc0001a9c20}, 0xc00020e7e0, 0x0, {0x0, 0x0}, {0x28ad5e0, 0xc0004a1090}, {0x0, 0x0, ...}, ...}, ...)
        /root/project/hugo/hugolib/hugo_sites.go:406 +0x766
github.com/gohugoio/hugo/hugolib.NewHugoSites({{0x28b0110, 0xc0001a9c20}, 0xc00020e7e0, 0x0, {0x0, 0x0}, {0x28ad5e0, 0xc0004a1090}, {0x0, 0x0, ...}, ...})
        /root/project/hugo/hugolib/hugo_sites.go:555 +0x158
github.com/gohugoio/hugo/commands.(*commandeer).loadConfig.func3()
        /root/project/hugo/commands/commandeer.go:498 +0x8d8
sync.(*Once).doSlow(0xc0004a1090?, 0x21926e1?)
        /usr/local/go/src/sync/once.go:74 +0xc2
sync.(*Once).Do(...)
        /usr/local/go/src/sync/once.go:65
github.com/gohugoio/hugo/commands.(*commandeer).loadConfig(0xc0006c8900)
        /root/project/hugo/commands/commandeer.go:423 +0xa4b
github.com/gohugoio/hugo/commands.newCommandeer(0x1, 0x1, 0x1, 0xc0002f9c20, {0x2891380?, 0xc00058e540}, 0xc00058db20, {0x0, 0x0, 0x0})
        /root/project/hugo/commands/commandeer.go:227 +0x31f
github.com/gohugoio/hugo/commands.initializeConfig(0x0?, 0x0?, 0x0?, 0x2176e62?, {0x2891380?, 0xc00058e540?}, 0x0?)
        /root/project/hugo/commands/hugo.go:125 +0x3b
github.com/gohugoio/hugo/commands.(*serverCmd).server(0xc00058e540, 0xc0008b2000, {0x0?, 0x0?, 0x0?})
        /root/project/hugo/commands/server.go:257 +0x1cd
github.com/gohugoio/hugo/commands.(*commandsBuilder).newServerCmdSignaled.func1(0xc0008b2000?, {0x37750f8?, 0x0?, 0x0?})
        /root/project/hugo/commands/server.go:96 +0x36
github.com/spf13/cobra.(*Command).execute(0xc0008b2000, {0x37750f8, 0x0, 0x0})
        /root/project/gomodcache/github.com/spf13/cobra@v1.6.1/command.go:916 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0xc0003f8900)
        /root/project/gomodcache/github.com/spf13/cobra@v1.6.1/command.go:1044 +0x3bd
github.com/gohugoio/hugo/commands.Execute({0xc0001163b0, 0x1, 0x1})
        /root/project/hugo/commands/hugo.go:92 +0xbd
main.main()
        /root/project/hugo/main.go:23 +0x56

It is an open issue. As in, it has not been implemented.

1 Like

thank you for the answer

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.