XML sitemap
It is possible to generate XML sitemaps for SEO purposes without using 3rd party plugins. When this feature is enabled, a sitemap index file is created with one or more sitemaps in it. By default, there will be one sitemap that contains all pages of the current site and language. You can render different sitemaps for each site and language.
Note
The XML sitemap is provided by the optional system extension EXT:seo. You can find information about how to install and use it in the EXT:seo manual.
Table of Contents
Installation
XML sitemaps are part of the "seo" system extension. If the extension is not
available in your installation, require it as described here: Installation, EXT:seo
Then include the static TypoScript template XML Sitemap .
How to access your XML sitemap
You can access the sitemaps by visiting https://.
The sitemap is a
typeNum page type,
selected by the type parameter. You will first see the sitemap index. By default, there is one sitemap in the
index. This is the sitemap for pages.
Note
Each siteroot and language configured in the site handling has its own XML sitemap depending on the entry point.
Example:
- Entry point
/-https://: for default languageexample. org/?type=1533906435 - Entry point
/fr/-https://: for Frenchexample. org/ fr/?type=1533906435 - Entry point
/it/-https://: for Italianexample. org/ it/?type=1533906435
How to setup routing for the XML sitemap
You can use the PageType decorator to map
the page type to a fixed suffix. This allows you to expose the sitemap with a
readable URL, for example https://.
Additionally, you can map the parameter sitemap, so that the links to the different
sitemap types (pages and additional ones, for example, from the news extension) are also mapped.
XmlSitemapDataProviders
The rendering of sitemaps is based on Xml. EXT:seo ships
with two Xml.
For pages
The
\TYPO3\ will generate a
sitemap of pages based on the detected siteroot. You can configure whether you
have additional conditions for selecting the pages. It is also possible to
exclude certain doktypes. Additionally, you may
exclude page subtrees from the sitemap (e.g internal pages). This can be
configured using TypoScript (example below) or using the constants editor in the
backend.
plugin.tx_seo {
config {
xmlSitemap {
sitemaps {
pages {
config {
excludedDoktypes = 3, 4, 6, 7, 199, 254, 255, 137, 138
additionalWhere = AND ({#no_index} = 0 OR {#no_follow} = 0)
#rootPage = <optionally specify a different root page. (default: rootPageId from site configuration)>
excludePagesRecursive = <comma-separated list of page IDs>
}
}
}
}
}
}
# ...
Note
The doktypes 137 and 138 in the example above are custom doktypes. The other doktypes given are the ones excluded by default by the SEO extension.
For records
If you have an extension installed and want a sitemap of those records, the
\TYPO3\ can be used. The
following example shows how to add a sitemap for news records:
plugin.tx_seo {
config {
<sitemapType> {
sitemaps {
<unique key> {
provider = TYPO3\CMS\Seo\XmlSitemap\RecordsXmlSitemapDataProvider
config {
table = news_table
sortField = sorting
lastModifiedField = tstamp
changeFreqField = news_changefreq
priorityField = news_priority
additionalWhere = AND ({#no_index} = 0 OR {#no_follow} = 0)
pid = <page id('s) containing news records>
recursive = <number of subpage levels taken into account beyond the pid page. (default: 0)>
url {
pageId = <your detail page id>
fieldToParameterMap {
uid = tx_myextension_pi1[news]
}
additionalGetParameters {
tx_myextension_pi1.controller = News
tx_myextension_pi1.action = detail
}
}
}
}
}
}
}
}
You can add multiple sitemaps and they will be added to the sitemap index automatically. Use different types to have multiple, independent sitemaps:
seo_googlenews < seo_sitemap
seo_googlenews.typeNum = 1571859552
seo_googlenews.10.sitemapType = googleNewsSitemap
plugin.tx_seo {
config {
xmlSitemap {
sitemaps {
news {
provider = GeorgRinger\News\Seo\NewsXmlSitemapDataProvider
config {
# ...
}
}
}
}
googleNewsSitemap {
sitemaps {
news {
provider = GeorgRinger\News\Seo\NewsXmlSitemapDataProvider
config {
googleNews = 1
# ...
template = GoogleNewsXmlSitemap.xml
}
}
}
}
}
}
# ...
Change frequency and priority
Change frequencies define how often each page is approximately updated and hence how often it should be revisited (for example: News in an archive are "never" updated, while your home page might get "weekly" updates).
Priority allows you to define how important the page is compared to other pages on your site. The priority is stated in a value from 0 to 1. Your most important pages can get an higher priority as other pages. This value does not affect how important your pages are compared to pages of other websites. All pages and records get a priority of 0.5 by default.
The settings can be defined in the TypoScript configuration of an XML sitemap by
mapping the properties to fields of the record by using the options
change and
priority.
change needs to point to a field containing string values
(see
pages
TCA definition of field
sitemap_),
priority needs to point to
a field with a decimal value between 0 and 1.
Note
Both the priority and the change frequency have no impact on your rankings. These options only give hints to search engines in which order and how often you would like a crawler to visit your pages.
Sitemap of records without sorting field
Sitemaps are paginated by default. To ensure that as few pages of the sitemap as possible are changed after the number of records is changed, the items in the sitemaps are ordered. By default, this is done using a sorting field. If you do not have such a field, make sure to configure this in your sitemap configuration and use a different field. An example you can use for sorting based on the uid field:
plugin.tx_seo {
config {
<sitemapType> {
sitemaps {
<unique key> {
config {
sortField = uid
}
}
}
}
}
}
Create your own XmlSitemapDataProvider
Changed in version 15.0 Breaking: #110334 - XML sitemap data provider interface changed
A data provider is a service that implements
Xml
with the single method
get. Before, a data provider
received its runtime information as constructor arguments and collected
its items in the constructor.
Deprecated since version 15.0 Deprecation: #110334 - AbstractXmlSitemapDataProvider
Abstract
still works, but triggers a deprecation message and will be removed in
TYPO3 v16. To support TYPO3 v14 as well, keep extending the base class
and implement the interface once support for TYPO3 v14 is dropped.
If you need more logic in your sitemap, write your own data provider. It
implements
Xml.
If
autoconfigure
is enabled in the file Configuration/Services.yaml of the extension,
TYPO3 finds the data provider through this interface. Without
autoconfigure, tag the service with seo.. As a
service, the data provider can use dependency injection in its constructor.
This data provider adds the records of an event table to the sitemap:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\XmlSitemap;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Seo\XmlSitemap\XmlSitemap;
use TYPO3\CMS\Seo\XmlSitemap\XmlSitemapDataProviderInterface;
use TYPO3\CMS\Seo\XmlSitemap\XmlSitemapRequest;
final readonly class EventProvider implements XmlSitemapDataProviderInterface
{
public function __construct(
private ConnectionPool $connectionPool,
) {}
public function getSitemap(XmlSitemapRequest $sitemapRequest): XmlSitemap
{
$configuration = $sitemapRequest->configuration;
$queryBuilder = $this->connectionPool
->getQueryBuilderForTable('tx_myextension_event');
$result = $queryBuilder
->select('uid', 'tstamp')
->from('tx_myextension_event')
->where($queryBuilder->expr()->eq(
'pid',
$queryBuilder->createNamedParameter(
(int)($configuration['pid'] ?? 0),
Connection::PARAM_INT,
),
))
->orderBy('uid')
->executeQuery();
$items = [];
while ($row = $result->fetchAssociative()) {
$items[] = ['uid' => $row['uid'], 'lastMod' => $row['tstamp']];
}
// The URLs are generated for the items of the requested page only
$contentObjectRenderer = $sitemapRequest->contentObjectRenderer;
$detailPid = (int)($configuration['detailPid'] ?? 0);
return XmlSitemap::forPage(
$items,
$sitemapRequest->page,
static fn(array $item): array => $item + [
'loc' => $contentObjectRenderer->createUrl([
'parameter' => $detailPid,
'additionalParams' => '&tx_myextension_event[event]=' . $item['uid'],
'forceAbsoluteUrl' => true,
]),
],
);
}
}
The method
get receives a
Xml with the name of
the sitemap, its configuration from TypoScript, the number of the requested
page of the sitemap, the request, and a content object renderer to generate
URLs with.
It returns a
Xml.
Xml takes all
items of the sitemap, selects the items of the requested page, and calculates
the last modification date and the number of pages for the sitemap index. The optional third argument maps
the items of the requested page, so URLs are only generated for these items,
and never for the sitemap index. A data provider that pages its items itself,
for example in its database query, uses
Xml instead.
The sitemap reads these keys of each item:
loc- The URL of the page to be crawled by a search engine. The example adds it in the mapper, so only the items of the requested page get a URL.
lastMod - The date of the last update of the item, as a Unix timestamp.
changefreqandpriority- Optional hints for search engines.
Register the data provider in TypoScript with its class name:
lib.contentElement {
templateRootPaths {
200 = EXT:my_extension/Resources/Private/Templates/ContentElements/
}
}
tt_content {
myextension_basiccontent =< lib.contentElement
myextension_basiccontent {
templateName = BasicContent
}
}
tt_content {
myextension_newcontentcsv =< lib.contentElement
myextension_newcontentcsv {
templateName = DataProcCsv
dataProcessing.10 = comma-separated-value
dataProcessing.10 {
fieldName = bodytext
fieldDelimiter.field = myextension_separator
fieldEnclosure = "
maximumColumns.field = imagecols
as = myTable
}
}
}
plugin.tx_seo.config.xmlSitemap.sitemaps.events {
provider = MyVendor\MyExtension\XmlSitemap\EventProvider
config {
pid = 42
detailPid = 43
}
}
Use a customized sitemap XSL file
The XSL file used to create a layout for an XML sitemap can be configured at three levels:
-
For all sitemaps:
EXT:my_extension/Configuration/Sets/Main/setup.typoscriptplugin.tx_seo.config.xslFile = EXT:my_extension/Resources/Public/CSS/mySite.xslCopied! -
For all sitemaps of a certain sitemapType:
EXT:my_extension/Configuration/Sets/Main/setup.typoscriptplugin.tx_seo.config.<sitemapType>.sitemaps.xslFile = EXT:my_extension/Resources/Public/CSS/mySitemapType.xslCopied! -
For a specific sitemap:
EXT:my_extension/Configuration/Sets/Main/setup.typoscriptplugin.tx_seo.config.<sitemapType>.sitemaps.<sitemap>.config.xslFile = EXT:my_extension/Resources/Public/CSS/mySpecificSitemap.xslCopied!
The value is inherited until it is overwritten.
If no value is specified at all, EXT:
is used as default.