Pager Aliases not in .Aliases

Where can I find the pager aliases? They aren’t in .Aliases.

I’ve tested with and without:

config/_default/hugo.toml:

[pagination]
  disableAliases = true

I’d like to write this to _redirects to do server side redirection, like the rest of my aliases.

/blog/page/1/index.html    /blog/
/blog/categories/page/1/index.html    /blog/categories/
/blog/categories/foo/page/1/index.html    /blog/categories/foo/
/blog/categories/bar/page/1/index.html    /blog/categories/bar/
/blog/categories/baz/page/1/index.html    /blog/categories/baz/

Here’s how I’m handling the rest of my aliases:

layouts/index.redir:

{{- /* https://www.netlify.com/docs/redirects/ */ -}}
{{-  range $p := .Site.Pages -}}
{{- range .Aliases -}}
{{- template "from" . }}	{{ $p.RelPermalink }}
{{ end -}}
{{- end -}}

{{- define "from" -}}
{{- if hasSuffix . ".html" -}}
  {{- . -}}
{{- else if hasSuffix . ".htm" -}}
  {{- . -}}
{{- else if hasSuffix . "/" -}}
  {{- . -}}index.html
{{- else -}}
  {{- . -}}/index.html
{{- end -}}
{{- end -}}

config/_default/hugo.toml:

disableAliases = true

This says “please disable my aliases”. That’s why you don’t have aliases in your page object… Or maybe I am misunderstanding your issue.

Note: Restart your hugo server if you change your config.

disableAliases

(bool) Whether to disable generation of alias redirects. Even if this option is enabled, the defined aliases will still be present on the page. This allows you to manage redirects separately, for example, by generating 301 redirects in an .htaccess file or a Netlify _redirects file using a custom output format. Default is false.

Right — and to clarify, even when disableAliases = true, aliases explicitly defined in front matter are still accessible in .Aliases. That’s how I’m handling all other redirects (as shown in the code I posted), and it’s working as expected.

The issue isn’t with defined aliases or server restarts.

The actual question is:

Where can I access pagination-generated aliases like /blog/page/1/, /blog/categories/foo/page/1/, etc.? These aren’t explicitly defined in content or front matter, and they don’t appear in .Aliases.

So:

  • Why don’t pagination aliases show up in .Aliases?
  • Is there another Hugo property or data structure where these are exposed so I can include them in _redirects?

You cannot.

If you want to you can disable their creation; they really don’t add any value:

[pagination]
  disableAliases = true

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