如何去除TYPO3 Solr结果列表链接中的&no_cache=1参数?
彻底移除TYPO3 Solr结果列表链接中的
&no_cache=1参数 环境信息
- TYPO3 10 + Solr 11.2 + PHP 7.4
- TYPO3 11 + Solr 11.5 + PHP 8.1
问题描述
Solr搜索结果列表容器内的链接会自动附加&no_cache=1参数,未主动配置该行为,疑似为扩展默认逻辑。已配置TYPO3_CONF_VARS[FE][disableNoCacheParameter] = true,仅能禁用该参数的缓存控制作用,但参数本身仍会显示在URL中,需彻底移除该查询变量。
解决方案
方法1:通过TypoScript调整Solr链接配置
直接覆盖Solr扩展的链接生成参数,精准清理no_cache变量:
plugin.tx_solr.search.targetPage.additionalParams { remove = no_cache }
该方法仅针对Solr搜索结果的链接生效,不会影响其他页面链接。
方法2:自定义中间件全局移除参数
通过TYPO3的请求中间件,在请求处理阶段全局移除URL中的no_cache参数:
- 注册中间件:在自定义扩展的
Configuration/RequestMiddlewares.php中添加:
return [ 'frontend' => [ 'yourvendor/remove-nocache' => [ 'target' => \YourVendor\YourExtension\Middleware\RemoveNoCacheParameter::class, 'after' => ['typo3/cms-frontend/site'], ], ], ];
- 创建中间件类:
<?php namespace YourVendor\YourExtension\Middleware; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; class RemoveNoCacheParameter implements MiddlewareInterface { public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $queryParams = $request->getQueryParams(); unset($queryParams['no_cache']); return $handler->handle($request->withQueryParams($queryParams)); } }
注意:此方法会全局移除所有请求的no_cache参数,若有特定场景需要保留,需添加条件判断。
方法3:覆盖Solr模板手动移除参数
复制Solr的结果链接模板到自定义扩展,修改链接渲染逻辑:
- 复制原模板
typo3conf/ext/solr/Resources/Private/Templates/Document/Result.html到typo3conf/ext/your_ext/Resources/Private/Templates/Document/Result.html - 修改链接部分,使用ViewHelper移除
no_cache参数:
<f:link.page pageUid="{settings.search.targetPage.pageUid}" additionalParams="{additionalParams -> f:remove(key:'no_cache')}" type="{settings.search.targetPage.typeNum}" > {document.title} </f:link.page>
该方法直接修改模板渲染逻辑,精准控制Solr结果链接的参数。
内容的提问来源于stack exchange,提问作者Stefan Padberg
相关产品推荐
相关产品推荐

