dmk / mk30xlegacy
DMK自动重定向到旧版/mirror/过时环境。
1.0.0
2023-04-25 06:20 UTC
Requires
- typo3/cms-core: ^11.5
Requires (Dev)
- captainhook/captainhook: ^5.10
- friendsofphp/php-cs-fixer: ^3.3
- helmich/typo3-typoscript-lint: ^2.5
- nimut/testing-framework: ^6.0
- php-parallel-lint/php-parallel-lint: ^1.3
- phpcompatibility/php-compatibility: ^10.x-dev
- phpmd/phpmd: ^2.11.1
- phpspec/prophecy-phpunit: ^2.0.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.1
- phpunit/phpunit: ^9.5
- pimple/pimple: ^3.5.0
- saschaegerer/phpstan-typo3: ^1.0
- sebastian/phpcpd: ^6.0
This package is auto-updated.
Last update: 2024-09-08 13:47:03 UTC
README
此TYPO3扩展在请求的uri在TYPO3中找不到时,会自动重定向到旧版域名。
简述其功能
- 注册一个中间件。
- 检查TYPO3响应的不可用状态码。
- 询问匹配器,对于要重定向的新或旧源uri
- PageTypeSuffixRemovalMatcher
检查url是否有后缀,以及url是否有无后缀的形式存在。
(核心站点匹配器找到uri或HEAD请求返回200状态码)。 - LegacyUriMatcher
检查请求uri是否在旧版域名中可用
(HEAD请求返回200状态码)。
- PageTypeSuffixRemovalMatcher
- 执行重定向到新uri。
安装
使用composer安装TYPO3。
从项目根目录运行
composer require dmk/mk30xlegacy
配置
基本配置通过扩展配置完成。
使用管理工具 > 设置 > 配置扩展模块来配置mk30xlegacy。
配置可以由站点配置或站点语言配置覆盖。
使用站点管理 > 站点模块来配置扩展。
- enabled
启用旧版重定向中间件。 (默认: 1) - responseMatchPattern
响应匹配模式:正则表达式,用于匹配当前请求的http响应码以执行旧版重定向。 (默认: [345]\d\d) - suffixRemovalSuffixes
页面类型后缀:从请求uri中移除的逗号分隔的后缀列表。 (默认: html,htm,xhtml) - redirectDomain
重定向域名:执行旧版重定向的域名。 - redirectDomainAvailabilityMatchPattern
旧版可用性匹配模式:正则表达式,用于匹配旧版检查的http响应码。匹配时将执行对旧版域名的重定向。 (默认: 2\d\d) - redirectResponseStatusCode
重定向响应HTTP状态码:用于重定向到旧版域名的HTTP状态码。 (默认: 307)
添加自定义匹配器
重定向中间件使用匹配器注册表,因此可以开发自定义匹配器。
class CustomMatcher implements MatcherInterface { public function isMatchableResponse(ResponseInterface $response): bool { // check here if this matcher is enabled for the typo3 response! return true; } public function matchRequest(ServerRequestInterface $request, ResponseInterface $response): UriResult { $result = new UriResult(); // add your custom stuff here, // to create an uri result (for redirect) // depending on the request and response return $result } }
在您的Services.yaml
中添加自定义匹配器
DMK\MyAwesomeExtension\Routing\Matcher\CustomMatcher: tags: - name: 'mk30xlegacy.routing.matcher' priority: 100
自定义旧版uri操作
您可以在执行LegacyUriMatcher可用性检查之前注册事件监听器,通过您的自定义方式操作旧版url(我们建议使用自定义匹配器!)
class LegacyUriMatchEventListener { public function __invoke(UriMatchPreAvailabilityCheckEvent $event): void { $uri = $event->getResult()->getUri(); // manipulate the url here, add query parameters for example. $uri = $uri->withQuery('?legacy=redirect&'.$uri->getQuery()); $event->getResult()->setUri($uri); } }
在您的Services.yaml
中添加自定义监听器
services: DMK\MyAwesomeExtension\Event\EventListener\LegacyUriMatchEventListener: tags: - name: 'event.listener' identifier: 'MyAwesomeLegacyUriMatchEventListener' event: DMK\Mk30xLegacy\System\Event\UriMatchPreAvailabilityCheckEvent