Feature #93606
closedDisable canonical URLs on a per page basis
Added by Aimeos no-lastname-given over 3 years ago. Updated over 3 years ago.
100%
Description
In TYPO3 9/10 it's only possible to disable canonical URL completely by unsetting the canonical URL provider.
Problem:
In Aimeos, we generate the HTML header ourselves including the canonical URL e.g. for the shop products. As it's not possible to disable generating the canonical URL on a per page basis, the HTML page served by TYPO3 will either contain only canonical URLs for the shop pages added by Aimeos or two canonical URLs in the HTML of the shop pages which is bad for SEO.
Updated by Georg Ringer over 3 years ago
- Related to Feature #93188: Possibility to disable hreflang per page added
Updated by Georg Ringer over 3 years ago
- Related to deleted (Feature #93188: Possibility to disable hreflang per page)
Updated by Aimeos no-lastname-given over 3 years ago
@Georg: Sorry, I don't see how config.disableHrefLang also disables canonical URLs because the patch disables alternate language URLs:
<link rel="alternate" hreflang="de" href="https://..." />
While I'm talking about SEO canonical URLs pointing to one page that's available with different URLs (not necessarily different languages):
<link rel="canonical" href="https://..." />
Updated by Richard Haeser over 3 years ago
Will add this to my todo.
But what is the reason that you don't use the official API's? You can use a PSR-14 event to define the canonical yourself. You can use the event ModifyUrlForCanonicalTagEvent
for that. I would not recommend doing it "yourself" as this will lead into the issue we always had: there is no way extensions can work together and define which extension should render the tag and might lead into duplicate tags (as you have now). I'm really looking for use cases which can't be done by the official API.
Updated by Gerrit Code Review over 3 years ago
- Status changed from Accepted to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/68258
Updated by Aimeos no-lastname-given over 3 years ago
Thanks for the patch!
We create a bunch of header tags in Aimeos if their content directly depends on the shop product data. Using the TYPO3 API would require us to fetch the data again from the database in the TYPO3 MVC controller which we want to avoid. Thus, in our case it's for performance reasons.
Updated by Richard Haeser over 3 years ago
So basically you want to be able to set the canonical (and href I guess) by a controller? I will think about if this is something that is already possible or otherwise if we can make this easily possible.
Updated by Aimeos no-lastname-given over 3 years ago
No, in our case we want to avoid setting the canonical URL in the controller for performance reasons. If we can disable it in the controller, we are totally fine.
Updated by Richard Haeser over 3 years ago
Well, my goal is that you should never ever set those tags manually yourself, but doing it by the official API. If I understand you correctly, using an EventListener will cause an extra db call in your situation while you have that information in the controller action isnt it? So if you can set the canonical link in your controller, that would be good isn't it? I assume you always want to have a canonical especially with products and categories in ecommerce.
Updated by Aimeos no-lastname-given over 3 years ago
Aimeos is a bit special because it supports multiple frameworks and applications. For that, the "controller" logic for retrieving the data and passing it to the views is encapsulated in a view model object (called "HTML Cllient"). In the TYPO3 MVC controller we don't have access to the product data any more because all TYPO3 MVC controller actions are dumb and only returning the response from the view model. Here's the TYPO3 MVC catalog controller where you can see the implementation:
https://github.com/aimeos/aimeos-typo3/blob/master/Classes/Controller/CatalogController.php#L48-L53
We pass a PSR-7 request to the view model and would return a PSR-7 response to TYPO3 but Extbase doesn't support that so it's still a string and the generated headers are added to the TYPO3 page here:
https://github.com/aimeos/aimeos-typo3/blob/master/Classes/Controller/AbstractController.php#L159-L167
As you can see, we don't have data from the view model in the TYPO3 MVC controller so offering a method to set the canonical tag there makes no sense for us. The ability to disable generating canonical tags is all we need.
Updated by Gerrit Code Review over 3 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/68258
Updated by Gerrit Code Review over 3 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/68258
Updated by Richard Haeser over 3 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset d9aeb6a5a3ad6296a89da24e2f5a1b98aa4fe0e8.