Introduction

About this document

The LinkValidator is provided by a system extension named linkvalidator which enables you to conveniently check your website for broken links.

This manual explains how to install and configure the extension for your needs.

What does it do?

The LinkValidator checks the links in your website for validity, reports broken links or missing files in your TYPO3 installation and provides a way to conveniently fix these problems.

It includes the following features:

  • The LinkValidator can check all kinds of links. This includes internal links to pages and content elements, file links to files in the local file system and external links to resources somewhere else in the web.
  • The LinkValidator checks a number of fields by default, for example header and bodytext fields of content elements. It can be configured to check any field you like.
  • The LinkValidator offers a just in time check of your website. Additionally the TYPO3 Scheduler is fully supported to run checks automatically. In this case you can choose, if you want to receive an email report, if broken links were found.
  • The LinkValidator is extendable. It provides hooks to check special types of links or override how the checking of external, file and page links works.

Screenshots

This is the Check Links backend module. It provides two actions: Report and Check Links. The Report action is always shown first. Here you can view the broken links which were found, when your website was last checked.

The Reports action

Viewing broken links in the Report action

The Check Links tab is used to check links on demand and can be hidden with TSconfig, if desired.

The Check links tab

Checking links live in the TYPO3 Backend

The workflow in the module is the following:

  • First you set the depth of pages you want to consider when checking for broken links in the Check Links tab. Then click the Check Links button.
  • Once the checks are done, the module automatically switches to the Report tab where the results are displayed.
  • The type and ID of the content containing the broken link become visible when you move the mouse over the icon for the content type. The pencil icons at the beginning of each row enable you to quickly fix the displayed elements.

The LinkValidator features full support of the TYPO3 Scheduler. This is the LinkValidator task:

The LinkValidator Scheduler task

Defining the LinkValidator task in the Scheduler

  • With this task you can run LinkValidator regularly via cron without having to manually update the stored information on broken links.
  • You can for example overwrite the TSconfig configuration. Without any change, the LinkValidator settings which apply for the respective pages will be used. If you set values there, the former will be overwritten.
  • The LinkValidator task can send you a status report via email. You can create your own email template as needed.

Credits

This extension is particularly based on the extension cag_linkchecker, which was originally developed for Connecta AG, Wiesbaden. cag_linkchecker is maintained by Jochen Rieger and Dimitri König.

Feedback

If you find a bug in this manual or in the extension in general, please file an issue in the TYPO3 bug tracker.

Working with LinkValidator

This page handles how to work with LinkValidator as editor. It is intended for a non-technical audience.

LinkValidator Report

  1. Access the module Check Links.
  2. Select the page you want to work on in the page tree
Access LinkValidator Report via "Check Links" module

Access LinkValidator Report via "Check Links" module

You will now see the Report with the list of broken links. In order to get results, select the checkboxes ("Internal Links", etc.) and choose the appropriate depth under Show this level. This will determine the page level, for example for depth This page, LinkValidator will only show broken links for the page that is currently selected in the page tree. The deeper you go, the more broken links may possibly be shown. After you change the settings, you must click Refresh display.

When you jump to a different page in the page tree, the Report will be refreshed.

Installation

This extension is part of the TYPO3 Core, but not installed by default.

Installation with Composer

Check whether you are already using the extension with:

composer show | grep linkvalidator
Copied!

This should either give you no result or something similar to:

typo3/cms-linkvalidator       v12.4.11
Copied!

If it is not installed yet, use the composer require command to install the extension:

composer require typo3/cms-linkvalidator
Copied!

The given version depends on the version of the TYPO3 Core you are using.

Classic installation without Composer

In an installation without Composer, the extension is already shipped but might not be activated yet. Activate it as follows:

  1. In the backend, navigate to the Admin Tools > Extensions module.
  2. Click the Activate icon for the LinkValidator extension.
Extension manager showing LinkValidator extension

Extension manager showing LinkValidator extension

Next step

LinkValidator uses the HTTP request library shipped with TYPO3. Please have a look in the Global Configuration, particularly at the HTTP settings.

There, you may define a default timeout. Generally, it is recommended to always specify timeouts when working with the LinkValidator.

Configuration

You can find the standard configuration in EXT:linkvalidator/Configuration/page.tsconfig.

This may serve as an example on how to configure the extension for your needs.

Minimal configuration

It is recommended to at least fill out httpAgentUrl and httpAgentEmail. The latter is only required if $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'] is not set.

mod.linkvalidator.linktypesConfig.external.httpAgentUrl =
mod.linkvalidator.linktypesConfig.external.httpAgentEmail =

Copied!

Reference

You can set the following options in the TSconfig for a page (for example the root page) and override them in user or groups TSconfig. You must prefix them with mod.linkvalidator, for example mod.linkvalidator.searchFields.pages = canonical_link.

searchFields.[key]

Property
searchFields.[key]
Data type
string
Description

Comma separated list of table fields in which to check for broken links. LinkValidator only checks fields that have been defined in searchFields.

LinkValidator ships with sensible defaults that work well for the TYPO3 core, but additional third party extensions are not considered.

Example
# Only check for "bodytext" in "tt_content":
tt_content = bodytext
Copied!
Default
pages = media,url
tt_content = bodytext,header_link,records
Copied!

linktypes

Property
linktypes
Data type
string
Description

Comma separated list of link types to check.

Possible values:

db: Check links to database records.

file: Check links to files located in your local TYPO3 installation.

external: Check links to external URLs.

This list may be extended by other extensions providing a custom linktype implementation.

Default
db,file,external

linktypesConfig.external.httpAgentName

Property
linktypesConfig.external.httpAgentName
Data type
string
Description
Add descriptive name to be used as 'User-Agent' header when crawling external URLs.
Default
TYPO3 LinkValidator

linktypesConfig.external.httpAgentUrl

Property
linktypesConfig.external.httpAgentUrl
Data type
string
Description
Add URL to be used in 'User-Agent' header when crawling external URLs.
Default
(empty string)

linktypesConfig.external.httpAgentEmail

Property
linktypesConfig.external.httpAgentEmail
Data type
string
Description
Add descriptive email used in 'User-Agent' header when crawling external URLs.
Default
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']

checkhidden

Property
checkhidden
Data type
boolean
Description
If set, disabled pages and content elements are checked for broken links, too.
Default
0

showCheckLinkTab

Property
showCheckLinkTab
Data type
boolean
Description

If set, the backend module shows a "Check Links" tab, which you can use to perform the checks on demand.

The Check links tab is visible

The Check links tab is visible

Default
1

actionAfterEditRecord

Property
actionAfterEditRecord
Data type
string
Default
recheck
Possible values
recheck | setNeedsRecheck
Description

After a record is edited, the list of broken links may no longer be correct, because broken links were changed or removed or new broken links added. Due to this, the list of broken links should be updated.

Possible values are:

  • recheck: The field is rechecked. (Warning: an RTE field may contain a number of links, rechecking may lead to delays.)
  • setNeedsRecheck: The entries in the list are marked as needing a recheck

mail.fromname

Property
mail.fromname
Data type
string
Description
Set the from name of the report mail sent by the cron script.
Default

Install Tool

defaultMailFromName

mail.fromemail

Property
mail.fromemail
Data type
string
Description
Set the from email of the report mail sent by the cron script.
Default

Install Tool

defaultMailFromAddress

mail.replytoname

Property
mail.replytoname
Data type
string
Description
Set the replyto name of the report mail sent by the cron script.

mail.replytoemail

Property
mail.replytoemail
Data type
string
Description
Set the replyto email of the report mail sent by the cron script.

mail.subject

Property
mail.subject
Data type
string
Description
Set the subject of the report mail sent by the cron script.
Default
TYPO3 LinkValidator report

linktypesConfig.external.headers

Property
linktypesConfig.external.headers
Data type
array
Description
Additional set of HTTP headers to be passed when crawling URLs.
Default
(empty array)

linktypesConfig.external.method

Property
linktypesConfig.external.headers
Data type
array
Description

This specified which method is used for crawling URLs. By default, we use HEAD (which falls back to GET if HEAD fails).

You can use GET as an alternative, but keep in mind that HEAD is a lightweight request and should be preferred while GET will fetch the remote web page (within the limits specified by range, see next option).

"The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response." (w3 RFC2616).

Default
HEAD

linktypesConfig.external.range

Property
linktypesConfig.external.headers
Data type
string
Description
Additional HTTP request header 'Range' to be passed when crawling URLs. Use a string to specify the range (in bytes).
Default
0-4048

linktypesConfig.external.timeout

Property
linktypesConfig.external.timeout
Data type
integer
Description

HTTP request option. This is the total timeout of the request in seconds.

If set, this overrides the timeout in $GLOBALS['TYPO3_CONF_VARS']['HTTP']['timeout'] which defaults to 0.

Default
20

Example

mod.linkvalidator {
        searchFields {
                pages = url,canonical_link
                tt_content = bodytext,header_link,records
        }
        linktypes = db,file,external
        checkhidden = 0
        mail {
                fromname = TYPO3 LinkValidator
                fromemail = no_reply@mydomain.com
                replytoname =
                replytoemail =
                subject = TYPO3 LinkValidator report
        }
        external {
                httpAgentUrl = https://example.com/info.html
                httpAgentEmail = info@example.com
        }
}
Copied!

Development

Implementation of a custom linktype

The LinkValidator uses so called linktypes to check for different types of links. Learn how to implement a custom linktype within an extension.

API

Overview of important classes and interfaces in the public API.

Custom linktypes

The LinkValidator uses so called "linktypes" to check for different types of links, for example internal or external links.

All "linktypes" have to implement the TYPO3CMSLinkvalidatorLinktypeLinktypeInterface.

Classes implementing the LinktypeInterface are automatically registered, if autoconfigure is enabled in Services.yaml.

Alternatively, one can manually tag a custom link type with the linkvalidator.linktype tag:

packages/my_extension/Configuration/Services.yaml
# Other definitions

MyVendor\MyExtension\Linktype\MyCustomLinktype:
  tags:
    - name: linkvalidator.linktype
Copied!

Due to the autoconfiguration, the identifier has to be provided by the class directly, using the method getIdentifier().

When extending TYPO3CMSLinkvalidatorLinktypeAbstractLinktype it is sufficient to set the $identifier class property.

Example

Add new linktype

You can find the following example in the extension t3docs/examples.

Extend TYPO3CMSLinkvalidatorLinktypeAbstractLinktype to create a custom linktype:

EXT:examples/Classes/LinkValidator/LinkType/ExampleLinkType.php
<?php

/*
 * This file is part of the TYPO3 CMS project. [...]
 */

namespace T3docs\Examples\LinkValidator\LinkType;

use TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype;

/**
 * This class provides Check Example Links plugin implementation
 */
class ExampleLinkType extends AbstractLinktype
{
    protected string $identifier = 'example';

    public function checkLink($url, $softRefEntry, $reference)
    {
        $isValidUrl = false;
        // TODO: Implement checkLink() method.
        return $isValidUrl;
    }

    public function getErrorMessage($errorParams)
    {
        $lang = $this->getLanguageService();
        return match ($errorParams['errno'] ?? 0) {
            404 => $lang->getLL('list.report.pagenotfound404'),
            // fall back to generic error message
            default => sprintf($lang->getLL('list.report.externalerror'), $errorParams['errno']),
        };
    }
}
Copied!

Activate the new linktype in the page tsconfig:

EXT:examples/Configuration/TsConfig/Page/Extension/Linkvalidator.tsconfig
mod.linkvalidator {
   # specify link types to be crawled
   linktypes = db,file,external,example
}
Copied!

The extension that provides the linktype must have a Configuration/Services.yaml file that contains either:

packages/my_extension/Configuration/Services.yaml
services:
  _defaults:
    autoconfigure: true
Copied!

Or if autoconfiguration is not desired for some reason:

packages/my_extension/Configuration/Services.yaml
services:
  MyVendor\MyExtension\LinkValidator\LinkType\ExampleLinkType:
    tags:
      -  name: linkvalidator.linktype
Copied!

Override the ExternalLinktype class

A new custom class should replace \TYPO3\CMS\Linkvalidator\Linktype\ExternalLinktype . The class inherits existing functionality from ExternalLinktype, but will be registered with the identifier "custom_external":

packages/my_extension/Classes/Linktype/ExternalLinktype.php
<?php

namespace MyVendor\NyExtension\Linktype\ExternalLinktype;

use TYPO3\CMS\Linkvalidator\LinkAnalyzer;
use TYPO3\CMS\Linkvalidator\Linktype\ExternalLinktype as LinkvalidatorExternalLinkType;

// This class inherits from ExternalLinktype,
// so it is only necessary to override some methods.
class ExternalLinktype extends LinkvalidatorExternalLinkType
{
    // This class must use a different identifier because "external" is already used.
    protected string $identifier = 'custom_external';

    public function checkLink(
        string $origUrl,
        array $softRefEntry,
        LinkAnalyzer $reference
    ): bool {
        // do additional stuff here or after parent::checkLink
        // ...
        return parent::checkLink($origUrl, $softRefEntry, $reference);
    }

    public function fetchType(array $value, string $type, string $key): string
    {
        preg_match_all(
            '/((?:http|https))(?::\\/\\/)(?:[^\\s<>]+)/i',
            (string)$value['tokenValue'],
            $urls,
            PREG_PATTERN_ORDER
        );
        if (!empty($urls[0][0])) {
            $type = $this->getIdentifier();
        }
        return $type;
    }
}
Copied!

Use the new linktype:

packages/my_extension/Configuration/page.tsconfig
mod.linkvalidator.linktypes = db,file,custom_external
Copied!

Since the identifier changes, the configuration should be copied to mod.linkvalidator.linktypesConfig.custom_external, so that it will be passed to the linktype, for example:

packages/my_extension/Configuration/page.tsconfig
mod.linkvalidator.linktypesConfig.custom_external < mod.linkvalidator.linktypesConfig.external
Copied!

Migration from TYPO3 11 LTS and below

Remove $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'] from your ext_localconf.php file.

If autoconfigure is not enabled in your Configuration/Services.(yaml|php), add the tag linkvalidator.linktype manually to your linktype service.

Additionally, make sure to either implement public function getIdentifier(): string or, in case your linktype extends AbstractLinktype, to set the $identifier class property.

AbstractLinktype

abstract class AbstractLinktype
Fully qualified name
\TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype

This class provides Check Base plugin implementation

getIdentifier ( )
returntype

string

setAdditionalConfig ( array $config)

Function to override config of Linktype. Should be used only if necessary. Add additional configuration to TSconfig.

param array $config

the config

fetchType ( array $value, string $type, string $key)

Base type fetching method, based on the type that softRefParserObj returns

param array $value

Reference properties

param string $type

Current type

param string $key

Validator hook name

getErrorParams ( )

Get the value of the private property errorParams

getBrokenUrl ( array $row)

Construct a valid Url for browser output

param array $row

Broken link record

Checks a given link for validity

param string $url

Url to check

param array $softRefEntry

The soft reference entry which builds the context of that url

param \\TYPO3\\CMS\\Linkvalidator\\LinkAnalyzer $reference

Parent instance

getErrorMessage ( array $errorParams)

Generate the localized error message from the error params saved from the parsing

param array $errorParams

All parameters needed for the rendering of the error message

LinktypeInterface

interface LinktypeInterface
Fully qualified name
\TYPO3\CMS\Linkvalidator\Linktype\LinktypeInterface

This class provides interface implementation.

getIdentifier ( )

Returns the unique identifier of the linktype

returntype

string

Checks a given link for validity

param string $url

Url to check

param array $softRefEntry

The soft reference entry which builds the context of that url

param \\TYPO3\\CMS\\Linkvalidator\\LinkAnalyzer $reference

Parent instance

setAdditionalConfig ( array $config)

Function to override config of Linktype. Should be used only if necessary. Add additional configuration to TSconfig.

param array $config

the config

fetchType ( array $value, string $type, string $key)

Base type fetching method, based on the type that softRefParserObj returns.

param array $value

Reference properties

param string $type

Current type

param string $key

Validator hook name

getErrorParams ( )

Get the value of the private property errorParams.

getBrokenUrl ( array $row)

Construct a valid Url for browser output

param array $row

Broken link record

getErrorMessage ( array $errorParams)

Generate the localized error message from the error params saved from the parsing

param array $errorParams

All parameters needed for the rendering of the error message

Hints for large sites

If you have a website with many hundreds of pages, checking all links will take some time and might lead to a time out. It will also need some resources so that it might make sense to do the check at night. If you want to check many pages, you should not use the "Check Links" tab in the backend module of LinkValidator. Use the TYPO3 Scheduler instead. The task provided by LinkValidator will cache the broken links just like the button "Check Links" would do. Afterwards you can use the backend module as usual to fix the according elements.

If you still want to check trees with many pages just in time, set the depth to a reasonable level like 2 or 3. Do not use "infinite".

Known problems

Sitemap