"Windows filename restriction" with alias

An alias like:
aliases: ["/?page_id=925/"]
makes the build fail on Windows because “?” character is not allowed in filenames.

I tried “cheating” by replacing ? by its encoded counterpart %3F, but then it’s not decoded back by the browser because the folder generated by Hugo is using %3F and not ?.

I know it’s not a Hugo caveat, but as a workaround I would like to disable aliases while not removing them from content files, so that it doesn’t make the build fail when I work on Windows ; then in production the build is on Linux via CI/CD so the alias should work (well I’m not sure because the character would need to be escaped apparently).

I know it’s very specific, but should we implement a config option or something to disable or work around “non OS friendly” aliases so that Hugo users can still build their project?

Otherwise I guess I’ll have to use server redirects.

I use a configuration directory to keep my development and production values separate. You could turn off aliases all the time, or just for development (hugo server).

I have a head cold, so it escapes me how to set env variables in Windows, but maybe you could set HUGO_DISABLEALIASES to true. That might work for your machine, code-free.

1 Like

It should do the job, thanks!

1 Like

Well now it is Netlify that doesn’t accept ? characters.

Deploying to live site URL...
Hashing files...
Error: Invalid filename ?page_id=929/index.html. Deployed filenames cannot contain # or ? characters
##[error]Docker run failed with exit code 2

I guess I’ll have to go with static/_redirects haha :slight_smile:

1 Like