Codeberg/pages-server
25
386
Fork
You've already forked pages-server
55

Do not redirect when appending .html to path #298

Open
opened 2024年03月12日 20:03:43 +01:00 by nicksellen · 5 comments

VitePress docs describe the feature nicely:

Some servers or hosting platforms (for example Netlify, Vercel, GitHub Pages) provide the ability to map a URL like /foo to /foo.html if it exists, without a redirect:

Netlify and GitHub Pages support this by default.
Vercel requires enabling the cleanUrls option in vercel.json.

https://vitepress.dev/guide/routing#generating-clean-url

It almost looks like the redirects feature could do it, but the syntax doesn't support removing the extension.

I found the redirect handling here

func(o*Options)matchRedirects(ctx*context.Context,giteaClient*gitea.Client,redirects[]Redirect,redirectsCachecache.ICache)(finalbool){

Is this something that you'd consider supporting?

Perhaps it'd be something like:

# in _redirects
/*.html /:splat 200

Or a way to support it automagically like netlify and GitHub pages?

VitePress docs describe the feature nicely: > Some servers or hosting platforms (for example Netlify, Vercel, GitHub Pages) provide the ability to map a URL like /foo to /foo.html if it exists, without a redirect: > > Netlify and GitHub Pages support this by default. > Vercel requires enabling the cleanUrls option in vercel.json. https://vitepress.dev/guide/routing#generating-clean-url It _almost_ looks like the [redirects feature](https://docs.codeberg.org/codeberg-pages/redirects/) could do it, but the syntax doesn't support removing the extension. I found the redirect handling here https://codeberg.org/Codeberg/pages-server/src/commit/a6e9510c078758794da5f6a1983b595bfc415de9/server/upstream/redirects.go#L66 Is this something that you'd consider supporting? Perhaps it'd be something like: ``` # in _redirects /*.html /:splat 200 ``` Or a way to support it automagically like netlify and GitHub pages?

Not quite what you asked for, but I noticed on my codeperg pages site that /foo redirects to /foo/ and displays /foo/index.html (at least if a /foo/index.html is available). To the end user that's the same result. You'd need to move the pages in similarly named directories, and old links to /foo.html would break.

Not quite what you asked for, but I noticed on my codeperg pages site that `/foo` redirects to `/foo/` and displays `/foo/index.html` (at least if a `/foo/index.html` is available). To the end user that's the same result. You'd need to move the pages in similarly named directories, and old links to `/foo.html` would break.

Yes, I've used that pattern before!

I don't think vitepress supports that, unless you manually put all your content in files like /foo/index.md - which would not be great, as would result in every page being called index.md.

I think I used to use a jekyll feature/plugin that did it automatically. In some ways it's nicer as it doesn't need any special webserver config. Aesthetically, I do prefer it without the trailing slash. /foo looks nicer than /foo/ to my eyes. Minor detail really though.

Given Netlify, GitHub, and Vercel all support it though, it seems not out of the question to implement it here too :)

Yes, I've used that pattern before! I don't _think_ vitepress supports that, unless you manually put all your content in files like `/foo/index.md` - which would not be great, as would result in every page being called `index.md`. I think I used to use a jekyll feature/plugin that did it automatically. In some ways it's nicer as it doesn't need any special webserver config. Aesthetically, I do prefer it without the trailing slash. `/foo` looks nicer than `/foo/` to my eyes. Minor detail really though. Given Netlify, GitHub, and Vercel all support it though, it seems not out of the question to implement it here too :)
This should work already: https://codeberg.org/Codeberg/pages-server/blame/branch/main/server/upstream/upstream.go#L130

Ah nice, I hadn't noticed that, thanks!

Although it issues a 307 redirect rather than serving up the page:

(repo: https://codeberg.org/nicksellen/pages-test)

whereas the feature I'm talking about is: the ability to map a URL like /foo to /foo.html if it exists, without a redirect

Ah nice, I hadn't noticed that, thanks! Although it issues a 307 redirect rather than serving up the page: - visit: https://nicksellen.codeberg.page/pages-test/woo - get redirected to https://nicksellen.codeberg.page/pages-test/woo.html (repo: https://codeberg.org/nicksellen/pages-test) whereas the feature I'm talking about is: _the ability to map a URL like /foo to /foo.html if it exists, **without a redirect**_
crapStone changed title from (削除) Support clean URLs (削除ここまで) to Do not redirect when appending .html to path 2024年05月28日 10:43:07 +02:00
crapStone added this to the v6.0 milestone 2024年05月28日 10:43:16 +02:00

Any chance this feature request will get into the new git-pages version?

It's not a question of Codeberg vs others, rather one of web-server behavior - it is called "Clean URLs" and the standpoint of some SSG authors like Jacky's Quartz 4 is that clean URLs are norm on the web these days.

The Clean URLs thing is not only required for folders where the web server would serve the folder's index.html page if it exists. It's highly relevant for leaf pages like blog posts as well. Manually updating the special _redirects file in each subfolder is tedious and error-prone.

@hw mentioned in #177 that he deployed a solution for git-pages v2.

What needs to be done to make this happen? So someone like me could contribute...

Any chance this feature request will get into the new git-pages version? It's not a question of Codeberg vs others, rather one of web-server behavior - it is called "Clean URLs" and the standpoint of some SSG authors like Jacky's Quartz 4 is that clean URLs are [norm on the web these days](https://github.com/jackyzha0/quartz/issues/591#issuecomment-1812934616). The Clean URLs thing is not only required for folders where the web server would serve the folder's `index.html` page if it exists. It's highly relevant for leaf pages like blog posts as well. Manually updating the special `_redirects` file in each subfolder is tedious and error-prone. @hw mentioned in #177 that he [deployed a solution](https://codeberg.org/Codeberg/Community/issues/177#issuecomment-56020) for git-pages v2. What needs to be done to make this happen? So someone like me could contribute...
Sign in to join this conversation.
No Branch/Tag specified
main
no-not-allow-for-new-users
pages
pages-custom-domain-update
ci_user-local-acme-service
feat/redis-caching
fix/memory-problem
v6.4
v6.3
v6.2.1
v6.2
v6.1
v6.0
v5.1
v5.0
v4.6.3
v4.6.2
v4.6.1
v4.6
v4.5
v4.4
v4.3
v4.2
v4.1
v4.0
v3.2.1
v3.2
v0.3.1
v0.3.0
v0.2.2
v0.2.1
v3.1
v3.0a
v3.0
v2.5b
v2.5a
v2.5
v2.4
v2.3
v2.2
v2.1
v2.0
v1.0_php
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Codeberg/pages-server#298
Reference in a new issue
Codeberg/pages-server
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?