HUGO

Aliases not working

I have

/content/drugs/drug1.md
/content/drugs/drug2.md

I am using in the front matter of both content files:

aliases = [
    "/drug1"
]
aliases = [
    "/drug2"
]

respectively.

When I generate the site and go to localhost:1313/drug1 or localhost:1313/drug2, I get a 404

How come the alias won’t work?

I want the page to be accessible by going to site.com/drugs/drug1

or

site.com/drug1 takes you to site.com/drugs/drug1

It works when I build the site on server. When I test locally, I don’t get this behavior as I expect.

Shall I use Permalinks settings? drugs = /:section/:slug? But I think that only affects that particular section

Repo is public: https://gitlab.com/hashborgir/psychedelicsdaily.com-hugo.git

It should work.

It’s hard to guess whad exactly is going wrong without seeing the whole site code, though. Consider sharing the repository.

I was making it public and it is now in the original post.

I switched to hugo serve and it’s working now! What is happening?!

When I use

hugo --ignoreCache --disableFastRender I get some issues sometimes.

Also, a few pages are still not showing up.

https://www.psychedelicsdaily.com/drugs/25t-4-nbome/ is OK

but

https://www.psychedelicsdaily.com/25t-4-nbome/ is 404

Works for me with hugo server.

You need to do something about lettercase of your aliases, though. /1B-LSD redirects to /drugs/1b-lsd (as you have written) :wink:

Yes, I was just about to ask about that.

How can I prevent slug from being lowercased or … I don’t know how hugo handles it.

What if I wanted the pages to be accessible at both lower case and uppercase?

https://www.psychedelicsdaily.com/25T-4-NBOMe does exist, doesn’t it?

Computers never do what you want them to do. They do what you ask them to do.

It does when you go to /drugs/25t-4-nbome

It seems they only work when going to the lowercase version of the name.

How can I have hugo also work it with uppercase? As in don’t modify the title to be slug lowercase? I don’t know.

If I go here to lowercase, that doesn’t show up either. But it does in /drugs/

There is a disablePathToLower option in config. Documented, too.

That seems like a global setting and not a per section setting.

Yes, it is a global one.

As far as I know, your best bet is to have two aliases for each drug page: ["/dRuGNaME", "/drugs/dRuGNaME"] should work really nicely.

I mean, trouble is, people could type in site.com/1p-lsd or 1P-lsd or 1P-LSD or 1P-lsd and I want them all to go to /drugs/1p-lsd

Is my only option nginx redirects?

Definitely not the only one: you can use apache redirects, too…

I don’t use Apache. I’m an Nginx guy. Should have said httpd redirects. :slight_smile:

Basically, yes, it you want real case-insensitivity, your best bet is handling it in the server. Which actually makes sense if you think hard of it: URLs are case-sensitive by design, and Hugo does what it is supposed to do here. Making it work from Hugo would require creating aliases for all the possible mixed-case scenarios for each page. It’s simply too much hassle for what can be done with a single line in server config.

Ok. I think I’m going to take off the aliases on these pages altogether. I have another section called /psychedelics/ where say /dmt/ is supposed to go, and that gives issues. Plus, it’s better for organization to leave them in /drugs. Or maybe eventually merge them in /psychedelics.

I have to think about this.

Thank you.

Hello.

In case anyone cares:

1: install nginx http lua module
2:

location ~ /drugs/[A-Z] {
    rewrite_by_lua 'ngx.exec(string.lower(ngx.var.uri))';
}