POC to redirect fragments/anchors

Created on 4 August 2020, almost 4 years ago
Updated 10 November 2023, 8 months ago

I know this request has been covered and closed in other issues e.g. https://www.drupal.org/project/redirect/issues/2396065 β†’ - this is just a POC for this functionality I thought I'd share in case anyone else finds it useful.

The use case was that I had a government client with a legacy site containing long pages (lots of regulatory content, bylaws etc) that were previously navigated by anchors, that were getting split into multiple shorter pages for better usability. There were lots of anchor links (same/other pages) within content and likely many users who had bookmarked anchor links. The client wanted to implement redirects for these.

It can be done via Javascript - a little hacky since it involves a second page load for the redirect, and won't serve any 3xx headers. It also involves an additional LIKE query by raw source path since (as stated in previous issues) the server can't obtain the requested fragment and so the generated hash in the request subscriber won't match any source path with a fragment. This additional query only runs if a non-fragment redirect is not found. (NB fragment redirects won't work if a non-fragment redirect exists, the latter will always take precedence).

This is a very rough pass and I have no idea what might happen re: loops and any other tests/validation.

✨ Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada bgilhome Victoria

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024