Is there an easier way to do this with permalinks?

Hey guys, I just refactored a site and I need to do 301 redirects for a few sections of the site since they now have a different path.

I’m currently using aliases on a few pages and that seems to work but some of the sections have many pages and I don’t want to have too go edit them manually and add an alias to each.

Can this be done with permalinks?

I’ve tried this in my confg.tml:

  perch-news = "/company/blog/:title"

  release-notes = "/company/release-notes/:filename"
  case-studies = "/company/case-studies/:title"

But that doesn’t seem to work just get a blank page or a 404 error page, each section has an file.

Any help is appreciated, thanks.

Are those sections? Try using Hugo’s language settings:
something like this, I think:

release-notes = "/company/release-notes/:filename"

actually, I just looked it up. I think it should work without the language setting. Maybe @regis knows?

Maybe I’m just misunderstanding how permalinks work, what I wanted to do was something like this:

Old site URL/Path:

release-notes = "/release-notes/:filename

perch-news = "/perch-news/:title"

New Site URL/Path

release-notes = "/company/release-notes/:filename"

blog = "/company/blog/:title"

But I still need release notes to be accessible via .SiteURL/release-notes and perch-news to be accessible via .SiteURL/blog is that what permalinks are supposed to do if so I never got it to work.

I just ended up moving things around to the way they were until I can figure out a way solve it via config permalinks otherwise I think I will just have to keep the structure I currently have :confused:

Thanks for replying :slight_smile:

Have you tried using aliases on your sections? You can now add FrontMatter to page section and therefore aliases, I never tried but it may suit your need…

Actually, I don’t think aliases work on section pages.

Yes, I added aliases to my sections by when you go to a page in that section using the alias does not seem to work :confused:

Thanks guys.

So, permalinks work on the pages within a section themselves, not the section. So if we reduce this to one case (I’m a little confused by the various paths you’ve got up there), what is one example folder that you have content in? And what is the output path you want that folder to go to?

So pages on old site were stored here:

release-notes = "/release-notes/:filename

perch-news = "/perch-news/:title"

They were accessible via .SiteURL/section-name

What I need to do is have those old links work with the new structure which is:

release-notes = "/company/release-notes/:filename"

blog = "/company/blog/:title"

So if a person goes to the old url for any article in the perch-news section it would still redirect to the new blog section if that makes sense.

So, for example, you have content in the folder release-notes and you have

release-notes = "/company/release-notes/:filename"

set in your config.

Your expected outcome is that the pages in the release-notes folder should be output to pages with this path: /company/release-notes/foo/index.html

Is that what you have and what you expect? That should work. The section index page will not change though.

My expectation was the opposite, so anything with the path:

/company/release-notes/:filename would render under .SiteURL/release-notes so I was misunderstanding how permalinks works.

Thanks for the clarification I guess I’ll keep the way I have it now then.

1 Like