0
votes

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. Can I make link like http://mydomain.tld/mypage/ via uriBuilder in Controller?

4
Have you found the solution? - Artur Cichosz

4 Answers

1
votes

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)

It can be in TS

config.tx_realurl_enable = 1

OR

it can be at .htaccess side

OR

you need to check your apache settings that might prevent generation of URL rewrite.

1
votes

I got the same problem in TYPO3 7.6.2 Configuration is OK, because the normal navigation is rendered with realurl. Just the URI that I get from uriBuilder is formatted without realurl.

Update: The problem arises when I use setCreateAbsoluteUri(true). Solution: make the url absolute afterwards.

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

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. The reason is, that the underlying typolink core method checks current host domain e.g. www.example.de with the requested path e.g. www.example.de/somesubdirectory. 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. I guess one might consider it as a bug.

So one solution might be to set config.absRefPrefix.

As I said above, this problem does not arise if run inside the server root directly.

0
votes

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. If you set it to 1, you end up having the index.php?id=xxx

Maybe this helps somebody who ends up here.