# How to setup a different slug types for different sections

**URL:** <https://discourse.gohugo.io/t/how-to-setup-a-different-slug-types-for-different-sections/41268>\
**Category:** support\
**Created:** [November 3, 2022, 3:18pm UTC](https://discourse.gohugo.io/t/how-to-setup-a-different-slug-types-for-different-sections/41268 "2022-11-03T15:18:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Utkarsh\_Sharma](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/utkarsh_sharma/32/18034_2.png) [@Utkarsh\_Sharma](https://discourse.gohugo.io/u/Utkarsh_Sharma)\
**Post date:** [November 3, 2022, 3:18pm UTC](https://discourse.gohugo.io/t/how-to-setup-a-different-slug-types-for-different-sections/41268/1 "2022-11-03T15:18:20Z")

</div>

My director structure is such  
-content  
|—blog  
-----||—blog1  
-----||—blog 2  
|—ideas  
-----||—ideas1  
-----||—ideas 2  
Resultantly my urls are  
-example.com/blog/blog1  
-example.com/ideas/ideas1  
i.e. (domain) / (section) / (slug)

I want the url structure to continue like as it is, for one section i.e. blogs. -example.com/blog/blog1  
However, set the URL structure for other just as the slug i.e. -example.com/ideas1 (domain) / (slug).

How do I achieve this ?

---

<div class="post-metadata">

**Author:** ![anon34553931](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@anon34553931](https://discourse.gohugo.io/u/anon34553931)\
**Post date:** [November 3, 2022, 5:44pm UTC](https://discourse.gohugo.io/t/how-to-setup-a-different-slug-types-for-different-sections/41268/2 "2022-11-03T17:44:46Z")

</div>

> [@Utkarsh\_Sharma](#):
>
> However, set the URL structure for other just as the slug i.e. -example.com/ideas1 (domain) / (slug).

Try the code below in your configuration file (I found it today also and put it in one section of my theme).

```auto
[permalinks]
ideas = "/:sections[1:]/:slug/"

```

Read More

> **[URL management](https://gohugo.io/content-management/urls/#permalinks-configuration-example)**
>
> Control the structure and appearance of URLs through front matter entries and settings in your site configuration.

---

<div class="post-metadata">

**Author:** ![Utkarsh\_Sharma](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/utkarsh_sharma/32/18034_2.png) [@Utkarsh\_Sharma](https://discourse.gohugo.io/u/Utkarsh_Sharma)\
**Post date:** [November 4, 2022, 2:50pm UTC](https://discourse.gohugo.io/t/how-to-setup-a-different-slug-types-for-different-sections/41268/3 "2022-11-04T14:50:12Z")

</div>

Thanks much, this works like a marvel

However, I read the docs again and I think this should also work and be more efficient:

```auto
[permalinks]
<section name> = "/:slug/"

```

and adding /:sections[1:]/ seems a bit unnecessary to me

Would love to hear your thoughts about it ?

---

<div class="post-metadata">

**Author:** ![anon34553931](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@anon34553931](https://discourse.gohugo.io/u/anon34553931)\
**Post date:** [November 4, 2022, 8:55pm UTC](https://discourse.gohugo.io/t/how-to-setup-a-different-slug-types-for-different-sections/41268/4 "2022-11-04T20:55:46Z")

</div>

Yo are misunderstanding the docs. Slug is the last part of the URL which is what you set in your front matter (or it defaults to the title). So, the part you don’t want in your URL will appear. You should test your suggestion before you conclude what I shared is unnecessary to remove doubt (I did test and it does not work as you expected. Mine works though). You explicitly said

> [@Utkarsh\_Sharma](#):
>
> However, set the URL structure for other just as the slug i.e. -example.com/ideas1 (domain) / (slug).

and that is what my solution does. Yours only shows title then slug.

---

<div class="post-metadata">

**Author:** ![wjh18](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wjh18/32/12661_2.png) [@wjh18](https://discourse.gohugo.io/u/wjh18)\
**Post date:** [November 5, 2022, 1:39am UTC](https://discourse.gohugo.io/t/how-to-setup-a-different-slug-types-for-different-sections/41268/5 "2022-11-05T01:39:07Z")

</div>

If you have an even deeper hierarchy and you only want the last section you can also do:

```auto
[permalinks]    
    blog = '/:sections[last]/:slug/'

```

Content created under `/blog/sub/subsub/` would have permalinks at `/subsub/` instead of `/sub/subsub/`. This achieves the same as your solution for `/blog/sub/` → `/sub/`.

FYI, this doesn’t change the permalink for the section list page (e.g. `/blog/sub/_index.md`). I haven’t found a way to achieve this with permalinks but a workaround is manually changing the URL in that page’s frontmatter (`url: sub`).

---

<div class="post-metadata">

**Author:** ![anon34553931](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@anon34553931](https://discourse.gohugo.io/u/anon34553931)\
**Post date:** [November 5, 2022, 8:19am UTC](https://discourse.gohugo.io/t/how-to-setup-a-different-slug-types-for-different-sections/41268/6 "2022-11-05T08:19:44Z")

</div>

Based on my understanding of the docs, `url` is relative to the root (domain). So, you are are correct about the sections. I went with `url` for my section pages.

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [November 7, 2022, 8:20am UTC](https://discourse.gohugo.io/t/how-to-setup-a-different-slug-types-for-different-sections/41268/7 "2022-11-07T08:20:18Z")

</div>

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