【问题标题】:TYPO3 routeEnhancers with suffix '.html' on rootpageTYPO3 routeEnhancers 在根页面上带有后缀“.html”
【发布时间】:2020-01-26 09:39:08
【问题描述】:

如果 routeEnhancers 配置了 '.html' 后缀,是否仍然无法选择像 'www.mysite.com' 这样的 baseurl?

在我看来,这应该是一个基本功能,但我找不到任何解决方案。重定向主页链接不是一种选择,因为规范仍然指向错误的 URL (www.mysite.com/index.html)

有什么解决办法吗?

我的配置如下:

routeEnhancers:
  PageTypeSuffix:
    type: PageType
    default: '.html'
    index: index
    map:
      .html: 0

【问题讨论】:

    标签: typo3 url-routing slug typo3-9.x


    【解决方案1】:

    reported issue on forge.typo3.org 仍然开放(截至 2019 年 9 月)。

    暂时,您可以提供一个自定义 PageType 装饰器,它可以达到预期的效果。报告此问题的开发人员 Daniel Dorndorf 发布了源代码:

    /Classes/Routing/Enhancer/CustomPageTypeDecorator.php

    <?php
    
    namespace Brand\Extensionname\Classes\Routing\Enhancer;
    
    use TYPO3\CMS\Core\Routing\Enhancer\PageTypeDecorator;
    use TYPO3\CMS\Core\Routing\RouteCollection;
    
    /**
     * Class CustomPageTypeDecorator
     */
    class CustomPageTypeDecorator extends PageTypeDecorator
    {
        public const IGNORE_INDEX = [
            '/index.html',
            '/index/',
        ];
    
        public const ROUTE_PATH_DELIMITERS = ['.', '-', '_', '/'];
    
        /**
         * @param \TYPO3\CMS\Core\Routing\RouteCollection $collection
         * @param array $parameters
         */
        public function decorateForGeneration(RouteCollection $collection, array $parameters): void
        {
            parent::decorateForGeneration($collection, $parameters);
    
            /**
             * @var string $routeName
             * @var \TYPO3\CMS\Core\Routing\Route $route
             */
            foreach ($collection->all() as $routeName => $route) {
                $path = $route->getPath();
    
                if (true === \in_array($path, self::IGNORE_INDEX, true)) {
                    $route->setPath('/');
                }
            }
        }
    }
    

    ext_localconf.php

    <?php
    defined('TYPO3_MODE') or die();
    
    // Register custom PageTypeDecorator:
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['enhancers'] += ['CustomPageType' => \Brand\Extensionname\Classes\Routing\Enhancer\CustomPageTypeDecorator::class];
    

    将此添加到您的模板扩展中,调整 PHP 命名空间 (\Brand\Extensionname\) 即可。

    config.yaml

    PageTypeSuffix:
      type: CustomPageType
      default: '.html'
      index: 'index'
      map:
        '.html': 0
    

    【讨论】:

      猜你喜欢
      • 2021-12-01
      • 2017-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-09
      • 1970-01-01
      • 2019-05-21
      相关资源
      最近更新 更多