Drupal core sets all link elements as HTTP headers, too. For example, if a page has the following in the element:
<link rel="canonical" href="/foo">
<link rel="shortlink" href="/node/1">
Then it might also have the following in the HTTP response headers:
Link: </foo>; rel="canonical", </node/1>; rel="shortlink"
This is done in `HtmlResponseAttachmentsProcessor.php`: http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/Render/HtmlR... . That code takes every `html_head_link` item and adds it to _both_ the HTML head and the HTTP header.
But in Metatags, the 'canonical_url' and 'shortlink' items are removed from `$build['#attached']['html_head_link']` if they are set for nodes (see metatag_entity_view_alter()). It adds them to to the HTML head using its own methods I guess, and it doesn't set the HTTP header at the same time.
I think that Metatag should add these HTTP response header links just like core does.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | metatag-n2908119-12.patch | 1.46 KB | damienmckenna |
Comments
Comment #2
jeffamHere's a patch that
stealsborrows some ideas from core to add HTTP Link headers for Canonical URL and/or Shortlinks set via Metatag.Comment #3
jeffamComment #4
benstallings commentedThe above patch appears to be incompatible with Drupal 8.4.
Comment #5
damienmckennaComment #7
benstallings commentedHere's an updated patch.
Comment #8
damienmckennaThanks, lets see what the testbot says.
Comment #9
lealex commentedminor bugfix
Comment #11
lealex commentedComment #12
damienmckennaRerolled, and a minor tweak.
Comment #13
damienmckennaI wonder, though, should *all* link tags be added to the header? I guess we can deal with that later.
Comment #14
damienmckennaComment #16
damienmckennaCommitted. Thanks!