简体   繁体   English

typo3 uriBuilder和realurl链接

[英]typo3 uriBuilder and realurl link

I create link to the page in controller like 我在控制器中创建到页面的链接

$uriPage = $this->uriBuilder->reset()->setTargetPageUid(intval($row['page']))->setCreateAbsoluteUri(TRUE)->build();

And get http://mydomain.tld/index.php?id=70 But I'm using realurl and need realurl link. 并获取http://mydomain.tld/index.php?id = 70,但我使用的是realurl,需要realurl链接。 Can I make link like http://mydomain.tld/mypage/ via uriBuilder in Controller? 我可以通过Controller中的uriBuilder进行诸如http://mydomain.tld/mypage/的链接吗?

I got the same problem in TYPO3 7.6.2 Configuration is OK, because the normal navigation is rendered with realurl. 我在TYPO3 7.6.2中遇到了同样的问题,配置正常,因为正常的导航使用realurl呈现。 Just the URI that I get from uriBuilder is formatted without realurl. 只是我从uriBuilder获得的URI的格式没有realurl。

Update: The problem arises when I use setCreateAbsoluteUri(true). 更新:当我使用setCreateAbsoluteUri(true)时出现问题。 Solution: make the url absolute afterwards. 解决方案:之后将URL设为绝对。

// ...
$this->uriBuilder->setCreateAbsoluteUri(false);
$link = $this->uriBuilder->build();
$uri = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($link);

This problem arises when the project is not beeing run inside the server root but in some subdirectory and additionally the TypoScript setting config.absRefPrefix is not set. 当项目不在服务器根目录中而是在某些子目录中运行时,并且没有设置TypoScript设置config.absRefPrefix就会出现此问题。 The reason is, that the underlying typolink core method checks current host domain eg www.example.de with the requested path eg www.example.de/somesubdirectory . 其原因是,底层typolink核心方法检查与所请求的路径例如www.example.de/somesubdirectory当前主机域例如www.example.de。 Because in case of missing setting from above they are different, the logic decides, that we are building a cross domain request URI, and any URL beautifier like RealUrl etc. are being skipped. 因为在上面缺少设置的情况下它们是不同的,所以逻辑决定我们正在构建一个跨域请求URI,并且将跳过诸如RealUrl等任何URL美化器。 I guess one might consider it as a bug. 我猜可能有人认为它是一个错误。

So one solution might be to set config.absRefPrefix . 因此,一种解决方案可能是设置config.absRefPrefix

As I said above, this problem does not arise if run inside the server root directly. 就像我上面说的,如果直接在服务器根目录下运行,则不会出现此问题。

The script you wrote to generate link is correct but you need to check configuration of realurl(Script will automatically generates that kind of URL) 您编写的用于生成链接的脚本是正确的,但是您需要检查realurl的配置(脚本会自动生成该类型的URL)

It can be in TS 可以在TS中

config.tx_realurl_enable = 1

OR 要么

it can be at .htaccess side 它可以在.htaccess端

OR 要么

you need to check your apache settings that might prevent generation of URL rewrite. 您需要检查可能会阻止生成URL重写的apache设置。

I'm a little late to this party, but anyway: 我参加这个聚会有点晚了,但是无论如何:

If you run into this problem, you might wanna check your typoscript. 如果您遇到此问题,则可能要检查您的打字稿。 There, you need to add 在那里,您需要添加

config.simulateStaticDocuments = 0

Then realurl should render the links correctly. 然后,realurl应该正确呈现链接。 If you set it to 1, you end up having the index.php?id=xxx 如果将其设置为1,则最终将拥有index.php?id=xxx

Maybe this helps somebody who ends up here. 也许这会帮助到这里的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM