Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paths like /post/example-post should serve example-post.html #89

Open
NathanRHD opened this issue Jul 25, 2022 · 6 comments
Open

paths like /post/example-post should serve example-post.html #89

NathanRHD opened this issue Jul 25, 2022 · 6 comments

Comments

@NathanRHD
Copy link

I actually think it's fairly standard practice outside of react or angular frameworks for paths like /post/example-post to go to example-post.html

This is a part of the modern web, I think.

If you look at the url for this pull request, for example, it is https://github.com/YunoHost-Apps/my_webapp_ynh/pull/76 without a file extension!

Originally posted by @NathanRussellUK in #76 (comment)

@Tagadda
Copy link
Member

Tagadda commented Jul 27, 2022

This app is not specifically aimed at React or Angular framework. Maybe a dedicated app is relevant ?
If not, adding a way to configure URL rewriting (through config panel?) should do the trick ?

@NathanRHD
Copy link
Author

NathanRHD commented Aug 1, 2022

This app is not specifically aimed at React or Angular framework. Maybe a dedicated app is relevant ?
If not, adding a way to configure URL rewriting (through config panel?) should do the trick ?

As I say, this is not a behaviour specific to react or angular, but a part of general patterns such as SPA, which are supported by Web standards via the history api:

https://developer.mozilla.org/en-US/docs/Web/API/History/pushState

yes, such configuration might be a good way to solve it!

@NathanRHD
Copy link
Author

@68kmentat
Copy link

Hi Nathan, if you want to implement clean URLs on your website, it is fairly simple. There are instructions at this website: https://www.hostnextra.com/kb/how-to-remove-html-extension-in-nginx
That example does exactly what you want, removing the ".html" from the URL. You want to add it to a newly created file at /etc/nginx/conf.d/nathanrhd.nohost.me.d/cleanurl.conf (you can use whatever filename you want)

@Garbulix
Copy link

Garbulix commented May 22, 2024

I confirm the problem and steps from the link (I needed to open it using Web Archive) didn't help me here. i will describe my case.

I have an Obsidian vault that I wanted to publish using Quartz generator. Generated website uses html files under-the-hood but links on the website doesn't have that .html suffix. In default my_webapp settings it leads to redirecting to YH login page as there is no site found.

I see try_files nginx function as the only way to fix that and based on official Quartz manual I modified automatically generated my_webapp.conf file for my site - I needed to edit it as creating a new config file in my_webapp.d/ lead to an error as try_files directive is already used for root location.

I changed line try_files $uri $uri/ /index.php?$args; into try_files $uri $uri.html $uri/ =404;.
As I understand the NGINX documentation, that should be enough, but instead of working links, when I click a note, my browser wants to download a file (without the extension). I guess there is another rule (higher in hierarchy) that forces to do something else when $uri file is not found (instead of checking $uri.html file).

See on my exemplary website https://example.do.lapy.pl/ - when you click on "note inside a folder" on left side, it downloads a file. As a note, when you adit the link into https://example.do.lapy.pl/folder/note-inside-a-folder.html, it works.

Quartz author won't change this behavior in his generator -> jackyzha0/quartz#591

@utkarshsethi
Copy link

Right now I'm achieving this on my own my_webapp by:

Creating the folder posts/hello-world and adding index.html to it such -> posts/hello-world/index.html instead of posts/hello-world.html

But it is of course an extra step per file unless you use an automated generator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants