Compatibility with URL rewriting?

I’m using so-called “ugly URLs” in Hugo to generate nice standard pages, with e.g. about.html, contact.html, and info.html pages. This gives me a clean, uncluttered file layout which is easy to navigate (no hundreds of folders just to contain different index.html files).

On the web server, I’m using URL rewriting to create my pretty URLs. For example, a web request for “/about” gets rewritten to “/about.html”, and the content gets served up correctly.

This all works fine, and I don’t think it’s anything out of the ordinary.

However, I want my Hugo content to be compatible with this URL rewriting setup. If I use something like {{ ref . "about.md" }} to link to a file, I want Hugo to output a URL compatible with the server’s URL rewriting, i.e. “/about” instead of “/about.html”.

I suppose essentially what I’m asking for is to have files generated according to uglyURLs=true, but URLs to be generated according to uglyURLs=false. Or alternatively, some way to specify the URL for pages but without changing the file that they get compiled to. I thought of the “url” front matter variable, but that actually seems to change the output file, which isn’t what I want.

Is there any way to do this? I’ve searched and haven’t found anything, which seems odd to me as I believe URL rewriting is very common. The only solution I can think of is to manually specify all URLs, which would work but would not be very maintainable when a lot of links are involved.

Any ideas? Thanks.

In what context are you using:

 {{ ref . "about.md" }}

It was just an example, but {{ ref . "about.md" }} would be used in templates, and {{< ref "about.md" >}} would be used in content pages. The problem is that with uglyURLs=true, Hugo generates the link as “/about.html”.

That would be the correct link, except I have URL rewriting on the server which means that “/about” should be the correct link. I want to know if there’s any way to get Hugo to generate this instead.

If you enter the md file ones as standard markdown does Hugo honor uglyurls? Can you force it by using HTML a tags?

Sorry, but I’m not quite understanding what you mean. If I write the URL directly, either in plain text or HTML, then Hugo doesn’t change it. I can get it to work this way. But the problem then is that it becomes a maintenance nightmare if I have many pages. For example, if I move or rename a file, I need to remember to manually change all hard-coded links to that file.

Ok, I can see what you mean if you have a lot of pages and don’t want to hardcode. Sorry, just throwing ideas out there.