Relative URLs, Redirects and Pagination

Are relativeURLs, redirects and pagination fundamentally at odds? I can’t seem to configure my site such that both work consistently. Possibly related to #2199 Investigate RelativeURLs=true and aliases

Let’s say I have relativeURLs enabled for the scenarios below.

I create a page with an alias and I do not have baseURL set. The generated alias doesn’t seem to bring along the relativeURL goodness:


title: Jobs in the Southeast
url: /work-with-us
    - /jobs

Generated alias page

<!DOCTYPE html>
    <!-- should be ../work-with-us/ -->
    <link rel="canonical" href="/work-with-us/"/>
    <meta name="robots" content="noindex">
    <meta charset="utf-8" />
    <meta http-equiv="refresh" content="0; url=/work-with-us/" />

Adding baseURL

With baseURL= I can get the aliases to work as expected, but then my pagination links break as it starts to mash together baseURL and relative paths.

<!-- redirect works as expected -->
<meta http-equiv="refresh" content="0; url=" />

<!-- should be ../articles/ -->
<a href="../southeast/southeast/articles/">1</a>

Customizing alias.html

I figured I could just customize my alias.html page in order to get around this. Unfortunately I can’t access the .Site or $.Site variables to access a site parameter.

<link rel="canonical" href="{{ .Site.Params.base }}{{ .Permalink }}" />

Error: Error building site: template: alias.html:6:36: executing "alias.html" at <$.Site.Params.base>: can't evaluate field Site in type struct { Permalink string; Page *hugolib.Page }

What about your other templates (for pagination), and config? Do you have a minimal example repo to reproduce this? It seems like you’d fix this in the pagination template, ne?

I need to set up a minimalist version of my repo to share here. The repo on GitHub is currently 7GB and I don’t expect folks to download to help me out.

I seem to have found a solution as you suggested. I reintroduced a baseURL variable in my site config and used {{ .URL | absURL }} to generate the pagination links. The baseURL variable seems to have been used to generate the aliases, too.


    <a href="" aria-label="Next" class="pagination-next">
      <span aria-hidden="true">&raquo;</span>

Alias (/jobs)

<!DOCTYPE html>
    <link rel="canonical" href=""/>
    <meta name="robots" content="noindex">
    <meta charset="utf-8" />
    <meta http-equiv="refresh" content="0;url=" />
1 Like