Friday, July 17, 2015

AEM Link Checker: fixing broken links that aren't broken.

If you run into a broken-link situation in AEM that leaves you scratching your head, this is why it happens and how to fix it.

Problem: When using AEM, you may notice that it automatically checks links and will not publish a broken link. In some ways, this is great, since AEM self-monitors and corrects for issues, but when you know the link is correct and it won’t let you write it, then there’s a problem.

Here are 4 types of links that I’ve written that have thrown errors:
  1. href="tel:123-456-7890"
  2. href="*|FORWARD|*"
  3. href="http://www.facebook.com/sharer/sharer.php?u=*|URL:ARCHIVE_LINK_SHORT|*"
  4. href="http://twitter.com/intent/tweet?text=*|URL:MC_SUBJECT|*: *|URL:ARCHIVE_LINK_SHORT|*"
Each of these are valid for different reasons, but will not resolve for the link checker because it either isn't recognized as a link (#1 and #2) or it is recognized as a link but AEM can’t resolve it for some reason (#3 and 4 end with Mailchimp variables, used in email newsletter templates).

With some research into the issue, I’ve found a couple of solutions. This is assuming that the link is indeed correct, should be published, and should not be rewritten by AEM.
  1. If the link has a special prefix (ex: #1 and #2)
    • Update the “Day CQ Link Checker Service” in the Web Console Config manager.
    • Add “tel:” and “*|” to Special Link Prefixes
      • When AEM comes across a link with this prefix, it will not check or rewrite it
      • Included by default on this list: javascript:, data:, mailto:, #, <!—, ${
  2. If the link has variables that will have post-processing (#3 and #4)
    • Add  x-cq-linkchecker=“skip” to the a tag
    • When AEM comes across a link with this information, it will not check or rewrite it
    • This code is most likely to be written at a component level and very unlikely at a author level; although it could be written on any link you can edit with HTML code
Exclusions by prefix patterns and explicit skips seems to be the best solution to address links that are going to occur frequently on the site and likely to cause errors. The link checker can be also turned off at a system (global) or page (local) level.

More information about the Link Checker:

No comments:

Post a Comment