TYPO3路由增强型根页面上带有后缀'.html'

时间:2019-09-26 07:01:06

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

如果routeEnhancercers配置了“ .html”后缀,是否仍然没有像“ www.mysite.com”这样的基本URL?

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

有什么解决办法吗?

我的配置如下:

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

1 个答案:

答案 0 :(得分: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