How to ensure "Redirect Comments To Node"

Created on 20 December 2024, 3 months ago

Since Drupal 8, the Redirect module has absorbed the former Global Redirect module.

Global Redirect had a checkbox on the configuration screen, "Redirect Comments To Node". This made sure that example.com/comment/{comment_id} redirects to example.com/clean-url#comment-{comment_id}, and it worked even if there were enough comments on a node to trigger a pager.

I cannot find that option anywhere in Redirect for Drupal 10 / 11.

Can anyone point me in the right direction? Or, if this module doesn't yet implement this, please say and we can change this to a feature request.

(grep -irl comment modules/contrib/redirect returns nothing, so I suspect this isn't implemented. But in terms of avoiding SEO duplication, this must be a common enough request that I'm thinking I must be missing the canonical way to do this.)

Thank you!

💬 Support request
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom JamesOakley Kent, UK

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

Comments & Activities

  • Issue created by @JamesOakley
  • 🇬🇧United Kingdom JamesOakley Kent, UK

    It turns out the feature in the old Global Redirect module was one I requested and then worked on. I'd completely forgotten. #1680978: Request to redirect URLs for comments to the parent node

  • 🇨🇭Switzerland berdir Switzerland

    Drupal 8+ does that by default, /comment/ID is a controller that nothing but redirect.

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • 🇬🇧United Kingdom JamesOakley Kent, UK

    Thanks @berdir

    In that case, I'll move this to the Core issue queue and change it to a bug.

    I've done a test, and here's how to reproduce:

    1. Download the latest core release (11.1.2 now) and install a new site with Standard Profile
    2. Create a new node of type Article, URL alias /test-article
    3. Scroll to the comments section at the bottom of the new article
    4. Create a new comment entitled "Test Comment"
    5. Click on the permalink for that comment
    • Expected behaviour: Browser goes to /test-article#comment-1
    • Actual behaviour: Browser goes to /comment/1#comment-1

    I'll now do some further tests with older core releases, starting with 8.0.0, to see when this regressed (assuming it did work at that point).

  • 🇬🇧United Kingdom JamesOakley Kent, UK

    OK, I couldn't easily test Drupal 8.0.0 because the oldest compatible PHP I could run on my development server was 7.4.

    So I installed Drupal 8.9.0, and had the same experience as above.

    So what happens to this issue next? I guess it depends:

    If the intention was always that comment permalinks would just be routes that redirect to the canonical URL for the page in question (as @berdir explained above), then it either never worked, or regressed somewhere between 8.0 and 8.9. In that case, this remains a Core issue, needs "Needs Tests" adding to spot any future regression, and is "Major" in priority because of the detrimental effect on SEO.

    If, in fact, this was never intended for core, then there are two options. Maybe this becomes a feature request for Core. Or maybe it needs to return to the Redirect module, where it becomes a bug report (since it's a regression from the Drupal 7 version).

    I think it's over to the Core maintainers to work out what kind of issue this is.

  • 🇬🇧United Kingdom JamesOakley Kent, UK

    Another "task" issue opened to request this issue be moved back to Active: 📌 Reopen "/comment/ID does not redirect to the canonical URL (3495377)" Active

  • 🇨🇭Switzerland berdir Switzerland

    Ok, looks like I was wrong, the permalink doesn't actually redirect, renders the parent node in a subrequest.

    I don't know why, but this is intentional which I think means this isn't a bug but a feature request.

    (In regards to redirect, a feature that existed in 7.x doesn't mean that it not existing in the 8.x version is a bug or regression).

    I'll leave this here for now, if there are valid reason for doing it like this then we could move it back, but it's not very likely that this will be reimplemented in redirect, certainly not without someone putting in the time to write the code and tests for it.

  • 🇬🇧United Kingdom JamesOakley Kent, UK

    Thanks. That takes me back a bit to working within the frameworks of a certain large commercial software company. "This feature is by design". You realise it's not a bug, it's a feature!

    See what anyone thinks. I may get a moment to look at Redirect myself to see if I can propose a MR over there.

    The history is that this used to be one of many features in the Global Redirect module, that did all that was needed to ensure you never got identical content from more than one URL. The main thing it did was to redirect /node/n to the canonical alias chosen for the node, but resolving comment URLs to the original node URL (with an anchor to get you to the right comment) was something else it did.

    When moving from D7->D8, Global Redirect was discontinued, and the D8+ version of Redirect included all the features of the old Global Redirect. So it was no longer needed, but for some reason this particular feature was never ported.

    It's not a regression at a code level. But in terms of the intent, sites no longer needing two different modules to handle (i) redirection in general and (ii) redirection to a canonical URL for SEO reasons, this feature needs to be included in Redirect to avoid a second module just for this.

Production build 0.71.5 2024