clickstorm / cs_seo

[clickstorm] SEO
Other
33 stars 49 forks source link

Set canonical URL to default news detail PID #310

Closed mschmitz89 closed 1 year ago

mschmitz89 commented 1 year ago

Hello all,

I have an installation where the same news could be output on different list pages and detail pages, because the news has e.g. several categories, which each have their own output page again. Therefore I would like to set the canonical URL of the news always to the default news detail page to reduce duplicate content.

Is this somehow possible?

Currently I just disable the canonical URL generation for news detail pages and reset the canonical URL myself, but with this the function to set the canonical URL for news manually is not working anymore, so now I am looking for a better solution.

[traverse(request.getQueryParams(), 'tx_news_pi1/news') > 0] config.disableCanonical = 1 page.headerData.20 = TEXT page.headerData.20 { wrap = typolink { parameter = 1234 returnLast = url forceAbsoluteUrl = 1 additionalParams.data = tx_csseo_url_parameters useCacheHash = 1 } } [end]

mhirdes commented 1 year ago

Hi,

you could use the same events as the cs_seo, to modify the URLs.

Here are the registered listener in Configuration/Services.yaml.

  Clickstorm\CsSeo\EventListener\CanonicalListener:
    tags:
      - name: event.listener
        identifier: 'cs-seo/canonical'
        event: TYPO3\CMS\Seo\Event\ModifyUrlForCanonicalTagEvent

  Clickstorm\CsSeo\EventListener\HrefLangListener:
    tags:
      - name: event.listener
        identifier: 'cs_seo/CsSeoHrefLang'
        after: 'typo3-seo/hreflangGenerator'
        event: TYPO3\CMS\Frontend\Event\ModifyHrefLangTagsEvent 

Then in your service you can check:

$metaDataService = GeneralUtility::makeInstance(MetaDataService::class);
$metaData = $metaDataService->getMetaData();
if(is_array($metaData) && empty($metaData['canonical']) && empty($metaData['no_index']) {
 ... do your own stuff
}