Skip to content

Add support for fragment redirects #2747

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Jul 8, 2025

This adds the ability to redirect URLs with # fragments. This is useful when section headers get renamed or moved to other pages.

This works both for deleted pages and existing pages.

The implementation requires the use of JavaScript in order to manipulate the location. (Ideally this would be handled on the server side.)

This also makes it so that deleted page redirects preserve the fragment ID. Previously if you had a deleted page redirect, and the user went to something like page.html#foo, it would redirect to bar.html without the fragment. I think preserving the fragment is probably a better behavior. If the new page doesn't have the fragment ID, then no harm is really done. This is technically an open redirect, but I don't think that there is too much danger with preserving a fragment ID?

Closes #2256

This adds the ability to redirect URLs with `#` fragments. This is
useful when section headers get renamed or moved to other pages.

This works both for deleted pages and existing pages.

The implementation requires the use of JavaScript in order to manipulate
the location. (Ideally this would be handled on the server side.)

This also makes it so that deleted page redirects preserve the fragment
ID. Previously if you had a deleted page redirect, and the user went to
something like `page.html#foo`, it would redirect to `bar.html` without
the fragment. I think preserving the fragment is probably a better
behavior. If the new page doesn't have the fragment ID, then no harm is
really done. This is technically an open redirect, but I don't think
that there is too much danger with preserving a fragment ID?
@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Jul 8, 2025
@ehuss
Copy link
Contributor Author

ehuss commented Jul 8, 2025

@GuillaumeGomez or @notriddle I don't suppose either of you would be willing to give this a light review?

One minor concern I had was about preserving the fragments on deleted pages, since that is somewhat of an open redirect. So for example, old-page.html#foo will now redirect to new-page.html#foo and preserve the #foo part in the redirect. Would you agree that should be safe?

@GuillaumeGomez
Copy link
Member

Is there a reason in particular we want to support this feature in the first place? Since mdbook is a static documentation generator, I'm not sure mdbook should be the one handling this case at all and should let it up to the server doing the rendering if any.

@ehuss
Copy link
Contributor Author

ehuss commented Jul 9, 2025

We don't have a reasonable ability to define server redirects with the rust-lang documentation.

@GuillaumeGomez
Copy link
Member

No we don't, and I'm not sure if we should. We keep older versions available (although my proposals on providing a GUI way to switch between versions were rejected) so that should cover this problem imo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: waiting on a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support fragments in redirects
3 participants