如何基于指定节点拆分TYPO3 tx_seo生成的站点地图?
Got it, let's tackle this sitemap timeout issue head-on. With thousands of pages, the default PagesXmlSitemapDataProvider is trying to process your entire page tree in one go—way too much for a single request to handle, hence the 503 error. Here's how you can split your sitemap into logical sections tied to specific page tree nodes, plus performance optimizations to keep things running smoothly:
1. Create a Custom Page Sitemap Provider (Root Node Filtering)
The default provider doesn't let you restrict pages to a specific root node out of the box, so we'll extend it to add that functionality.
First, create a custom data provider class in your sitepackage (e.g., Classes/XmlSitemap/CustomPagesXmlSitemapDataProvider.php):
<?php namespace YourVendor\EpochenapoleonSitepackage\XmlSitemap; use TYPO3\CMS\Seo\XmlSitemap\PagesXmlSitemapDataProvider; class CustomPagesXmlSitemapDataProvider extends PagesXmlSitemapDataProvider { /** * Override query to add root node filter */ protected function getQuery(): \TYPO3\CMS\Core\Database\Query\QueryBuilder { $query = parent::getQuery(); // Add rootUid filter if configured if (!empty($this->config['rootUid'])) { $query->andWhere( $query->expr()->eq('root', $query->createNamedParameter($this->config['rootUid'], \PDO::PARAM_INT)) ); } // Or use pidInList if you want to target specific parent pages instead of root nodes if (!empty($this->config['pidInList'])) { $query->andWhere( $query->expr()->in('pid', $query->createNamedParameter(explode(',', $this->config['pidInList']), \TYPO3\CMS\Core\Database\Connection::PARAM_INT_ARRAY)) ); } return $query; } }
2. Configure Split Sitemaps in tx_seo
Now update your plugin.tx_seo configuration to define multiple sitemap sections, each tied to a specific root node or parent page. For example, if you have major sections rooted at UIDs 2, 5, and 10:
plugin.tx_seo { config { xmlSitemap { epochenapoleon { # Section 1: Pages under root node UID 2 pages_section1 { provider = YourVendor\EpochenapoleonSitepackage\XmlSitemap\CustomPagesXmlSitemapDataProvider config { excludeDoktypes = 9818, 9819, 1789, 654, 656, 7076 additionalWhere = no_index = 0 rootUid = 2 # Target this root node's entire subtree } } # Section 2: Pages under root node UID 5 pages_section2 { provider = YourVendor\EpochenapoleonSitepackage\XmlSitemap\CustomPagesXmlSitemapDataProvider config { excludeDoktypes = 9818, 9819, 1789, 654, 656, 7076 additionalWhere = no_index = 0 rootUid = 5 } } # Section 3: Pages under parent UIDs 10, 12 (use pidInList instead) pages_section3 { provider = YourVendor\EpochenapoleonSitepackage\XmlSitemap\CustomPagesXmlSitemapDataProvider config { excludeDoktypes = 9818, 9819, 1789, 654, 656, 7076 additionalWhere = no_index = 0 pidInList = 10,12 # Target pages directly under these parents (and their subpages) } } # Keep your existing news sitemap news { provider = TYPO3\CMS\Seo\XmlSitemap\RecordsXmlSitemapDataProvider config { table = news_table sortField = sorting lastModifiedField = tstamp additionalWhere = AND (no_index = 0 OR no_follow = 0) pid = 25,26 url { pageId = 28 fieldToParameterMap { uid = tx_extension_pi1[news] } additionalGetParameters { tx_extension_pi1.controller = News tx_extension_pi1.action = detail } useCacheHash = 1 } } } } } } }
3. Verify the Sitemap Index
Once you've added these sections, visit domain.tld/sitemap.xml—it should now show an index of all your split sitemaps (each section will have its own URL like domain.tld/sitemap.xml?section=pages_section1). Each individual sitemap will only contain pages from its targeted node, keeping the file size and generation time small enough to avoid timeouts.
4. Extra Performance Tweaks
- Enable Sitemap Caching: TYPO3 can cache sitemap output to avoid regenerating it on every request. Add this to your config:
plugin.tx_seo.config.xmlSitemap.cache = 1 plugin.tx_seo.config.xmlSitemap.cacheLifetime = 86400 # Cache for 24 hours - Optimize Database Queries: Add database indexes for fields used in your sitemap queries (e.g.,
root,no_index,tstamp,pid) to speed up page fetching. - Adjust Server Timeouts: As a temporary fix, bump up PHP's
max_execution_timeand your web server's (Apache/Nginx) timeout settings, but splitting the sitemap is the long-term solution.
内容的提问来源于stack exchange,提问作者EPOCHENAPOLEON

