Special characters in Aliases?

Is it possible to use alieas like the following in hugo:

/posts/%uXFgd1yKSu0eFhyEcLEovreymGzEWdSNTaq8jyrQ86s=.sha256

I also tried escaping the special letter to make it url safe like

/posts/%25uXFgd1yKSu0eFhyEcLEovreymGzEWdSNTaq8jyrQ86s%3D.sha256

However neither worked. I got a 404 error.

To use a file extension of any kind that is not HTML you will have to add an output format. Look at the following docs and come back here if that does not help you:

“.sha256” is not file extention but just part of string I want to use as the URL. I don’t mean to output an actual file.

The thing is the dot. That probably will tell hugo it’s a file ending. Not sure how to work around this.

content

+++
title = "Test"
date = 2021-04-03T05:16:02-07:00
draft = false
aliases = [
  "/posts/%uXFgd1yKSu0eFhyEcLEovreymGzEWdSNTaq8jyrQ86s=.sha256"
]
+++

Now run hugo.

public/posts/
└── %uXFgd1yKSu0eFhyEcLEovreymGzEWdSNTaq8jyrQ86s=.sha256
    └── index.html

Hugo doesn’t have a problem with the percent sign or the period when rendering the site.

Now run hugo server and access the page in the browser, using an encoded url:

http://localhost:1313/posts/%25uXFgd1yKSu0eFhyEcLEovreymGzEWdSNTaq8jyrQ86s=.sha256

Initially I received a “400 Bad Request” error, and the %25 in the browser’s address bar was rewritten to %. Then I pasted the URL in to the address bar again and it started working. So my theory is that the built-in web server is behaves inconsistently with URLs like this.

To prove my theory, I published my test pages to an Apache site, and hit the page from both Chrome and Firefox. I was redirected without error on both.

https://mooring.com/posts/%25uXFgd1yKSu0eFhyEcLEovreymGzEWdSNTaq8jyrQ86s=.sha256

I’ll keep this link alive for the next seven days.

1 Like

It works! Thank you very much! I didn’t think it could be caused by the build in server.

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