typo3 - TYPO3 routeEnhancers 在根页面上带有后缀“.html”
问题描述
如果 routeEnhancers 配置了“.html”后缀,是否仍然没有选择像“www.mysite.com”这样的 baseurl?
在我看来,这应该是一个基本功能,但我找不到任何解决方案。重定向主页链接不是一种选择,因为规范仍然指向错误的 URL (www.mysite.com/index.html)
有什么解决办法吗?
我的配置如下所示:
routeEnhancers:
PageTypeSuffix:
type: PageType
default: '.html'
index: index
map:
.html: 0
解决方案
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\
),您就完成了。
配置.yaml
PageTypeSuffix:
type: CustomPageType
default: '.html'
index: 'index'
map:
'.html': 0
推荐阅读
- python - openpyxl 在更新工作表中的值时正在删除数据透视表
- javascript - 如何使用 Web 应用程序进行室内地理定位?
- typescript - Typescript 接口未重载/合并后续接口字段
- javascript - 无法在javascript中反转字符串
- r - R 错误:“闭包”类型不能被强制为“双倍”
- react-admin - 问题访问由 React-Admin 中的父级传递的属性
- python - 在python中填充整个数据框值
- excel - excel表格中每组的总数
- sql - 实体框架 Skip 和 Take 未转换为 SQL 命令
- sql - '*' 附近的语法不正确。(消息 102,第 15 级,状态 1,第 5 行)