TYPO3强制跨域网页的内部链接在新闻中使用https [英] TYPO3 force internal links to cross domain pages to use https in news
问题描述
我的TYPO3网站有多个域,其中包含从内部新闻到另一个域中另一个域的链接。
my TYPO3 website has multiple domains that have links from internal news to another a page in another domain.
Domain A (with SSL in frontend)
Page 1
News (folder)
News A
News B
Domain B (with SSL in frontend)
Page 2
Page 3
新闻A中的链接
到第1页工作得很好,但是当从新闻B链接到
或
时,网址是生成正确,但该方案始终 http
:
Links in News A
to Page 1 work perfectly fine, but when linking from News B to Page 2
or Page 3
, the url is generated properly, but the scheme is always http
:
示例新闻A
:
< a href =/ Page-1.html> Page 1< / a>
示例新闻B
:< a href =http://domain-b/Page-2.html >>< / a>
有没有办法将网址生成配置为在链接到任何内容时始终使用https作为方案在给定的域名?我怀疑必须在tx_news中进行链接渲染吗?
Is there a way to configure the url generation to always use https as scheme when linking to anything in a given domain? I suspect that this has to be done for the link rendering in tx_news?
推荐答案
这与新闻扩展无关但是是TYPO3本身的一个错误 - 或者让它称之为缺失功能,因为TYPO3在这个地方不知道其他域应该使用 https
作为协议。
This has nothing to do with the news extension but is a bug in TYPO3 itself - or let's call it a missing feature because TYPO3 doesn't know at this place that the other domain should be use https
as protocol.
我要解决的问题是在输出内容之前替换内容。这可以通过在 ext_localconf.php
中添加一个钩子来完成:
What I do to solve this is a replace on the content before it is outputted. This can be done with adding a hook in the ext_localconf.php
:
// Hook for changing output before showing it
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-output'][]
= \Vendor\ExtKey\Hooks\Frontend\ContentPostProc::class . '->run';
和文件 typo3conf / extkey / Classes / Hooks / Frontend / ContentPostProc
:
namespace Vendor\ExtKey\Hooks\Frontend;
namespace Vendor\ExtKey\Hooks\Frontend;
class ContentPostProc
{
public function run(array &$parameters) {
$searchReplace = [
'http://domain.tld' => 'https://domain.tld'
];
$parameters['pObj']->content = str_replace(array_keys($searchReplace), array_values($searchReplace), $parameters['pObj']->content);
}
}
这篇关于TYPO3强制跨域网页的内部链接在新闻中使用https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!