Alias redirect issues with a "sub-domain" base URL


#1

We use Hugo v0.30.2 to generate online documenation for base URL www.company.com/docs/ where www.company.com is the URL of the company’s WordPress site. This works, but I’ve now encountered a problem:

I added the following alias definition in an xxx/targetpage.md content file:

aliases:
  - "/xxx/sourcepage/"

On the local server, http://localhost:1313/xxx/sourcepage/ is succesfully redirected to http://localhost:1313/xxx/targetpage/. But on the company site, www.company/docs/xxx/sourcepage/ is redirected to www.company/xxx/targetpage/ instead of to www.company/docs/xxx/targetpage/ — i.e., docs/ is missing from the path, which results in a Page Not Found error.

I see that Hugo created an xxx/sourcepage/index.html file that has an HTML <head> element with <link rel="canonical" href="/xxx/targetpage/"/> and <meta http-equiv="refresh" content="0; url="/xxx/targetpage/" /> elements. If I manually edit the URL paths in these elements to ../xxx/targetpage/, the redirect succeeds.

We set baseURL in config.toml to "" and then set it dynamically using Gulp and JavaScript. We also set canonifyURLs and relativeURLS to true, and uglyurls to false.


#2

This is by design. The aliases are used as they are. There is no (easy) way we can guess what you mean.


#3

But I’m not asking Hugo to guess. My assumption, based also on the examples in the Hugo documentation, is that an alias that begins with / is relative to the configured base URL. So, for example, an /xxx/ alias would redirect http://localhost:1313/xxx/ when using the local server, but would redirect www.company.com/docs/xxx/ for a site built with base URL www.company.com/docs/. Isn’t this the case?


#4

No, your assumption is wrong.There is no logic in the alias parsing, as that would break pretty fast.

Also, even if you think this should have behaved differently, we cannot change it.


#5

Are the following alias values expected to work?

  1. A relative URL such as ../../xxx/.
  2. An abosolute URL such as http://www.company.com/docs/xxx?