Handle Params in URL

Hey,

In Hugo how do I get parameters to work like htaccess files?

For example:

this page: mysite.com/product/prinaple

I want this to go to mysite.com/product/ and then somewhere on the page I can check if it exists and do something with it. If not exists show fallback.

Does this make sense?

That is something you do server side not with Hugo.

I gathered .htaccess is server side as its apache, I was asking for a similar approach in Hugo, is there one?

Nope. Hugo is just a generator.

However, you can do client-side redirection via JavaScript (though it is not advisable). Redirection should be done server-side.

Not exactly, but it depends on what you want to do with your .htaccess-like file. Keep in mind you can write to any text-based file using custom outputs, so while Hugo just generates files and it’s up to you to decided on the server, you can use Hugo’s flexibility to your advantage. For example, with setting up redirects:

1 Like

This is what I want to do and what I currently do in my htaccess.

REDIRECT mysite.com/about/careers -> mysite.com/about?p=careers

^not actual htaccess code but it highlights my desire.

This was, the page about is called, I have a script that tells me if p is set and get the value of p, then if p is careers I do something. The user sees in the address bar: mysite.com/about/careers

Also, I use htaccess to remove extensions like .php or html… Is this possible?

Did you try Hugo’s aliases?