Section-Link pointing the current page not rendering without config.baseURL
- Have a typolink, e.g. created in a textmedia-element, that points to the same site to a different content element. The typolink should look something like <a href="t3://page?uid=123#456">Link to content element on the current page</a>, where 123 is the current site.
- The base-tag on the site gets set via page.headerData in order to dynamically get BaseVariants from the SiteConfiguration. Works nicely without needing additional conditions or configurations. The TypoScript setting config.baseURL is not used.
- Link will be rendered incorrectly in the frontend. It will point to the root-URL of the current SiteConfiguration without the current path segment. E.g. if the page would be located under my/path/segment/ and the dynamically set base-URL is https://www.mypage.com, the link should be https://www.mypage.com/my/path/segment#456, it is rendered however like https://www.mypage.com/segment#456. Incorrect link and redirect when clicking.
- The Method generateUrlForPageWithSiteConfiguration of the class PageLinkBuilder checks if the TypoScript setting config.baseURL is set. If it is not set, then the URL is rendered incorrectly to the root-URL.
- Setting config.baseURL resolves the problem. The link will then be rendered correctly.
- However: As far as I can see, it is not possible to easily work with SiteConfigurations and BaseVariants with the config.baseURL-Setting.
- If I am not mistaken, one would have to use e.g. TypoScript-Conditions for each variant to set config.baseURL. This seems pretty cumbersome. It is also not very nice to introduce lots of conditions depending on the URL into your setup.
- Either there is a configuration method, that I have not considered yet, or the config.baseURL should be changed to be able to dynamically set it.
- Or adjust the generateUrlForPageWithSiteConfiguration method?
Updated by Benni Mack over 1 year ago
- Status changed from New to Needs Feedback
this is actually expected behavior. TYPO3 does not (and cannot) know that you set a `<base>` tag yourself.
Setting config.baseUrl dynamically was possible (or is still possible) with TypoScript conditions. It is also possible if you use a hook to dynamically set TSFE->baseUrl.
The <base> tag isn't respected by a lot of crawlers, resulting in a lot of errors in your server log, so the recommendation is to work with config.absRefPrefix which is set dynamically from the site configuration.
Can you explain why you need the <base> tag?
Updated by Philipp Seiler over 1 year ago
If I remember correctly, I needed it because of dynamically created Anchor-Tags that point to some elements on the current page. Without the base-tag, the anchor-links would trigger a site-reload, the desired behavior however was to jump directly to some anchor.
I do use TypoScript conditions now to set the correct base-tag.
I guess this problem this is somewhat of an edge-case and can probably be discarded.