How to rewrite news-urls in TYPO3 v9

Realurl is gone, try this instead

It seams the TYPO3 core team decided to drop realurl and integrate it into the core of typo3. We were shocked at first, because we have perfected our realurl configuration over the years. Do we need to redevelop our realurl config? Hell yes.
Ok, all drama aside. We like the progress TYPO3 is making the last years. We have been fans of TYPO3 since 2005. We were a bit baffled to now find realurl in t3 9.5. However we were confident there will be a really nice, better replacement for it.

It starts with the Site Management menu item

There is a new menu item in the backend, called Site Management. There are two options: Sites, and Redirect. We only need the Sites tab this time.
You will have to create a new "site configuration" first. See attached screenshot.
After adding the site configuration, a folder called typo3conf/sites was created on the filesystem. We know this because we were checking the filesystem with git.
This is because we called the "Site identifier" site. We choose to have this really generic name because of our CI setup.
The contents or the typo3conf/sites/site/config.yml are the following:
rootPageId: 4
base: 'https://www.danielknows.com'
baseVariants: {  }
languages:
  -
    title: English
    enabled: true
    languageId: '0'
    base: /
    typo3Language: default
    locale: en_US.UTF-8
    iso-639-1: ab
    navigationTitle: ''
    hreflang: ''
    direction: ''
    flag: us
errorHandling: {  }
routes: {  }
After we installed News we realized we needed to change this file, since it also does a lot of things in the url-rewriting department.
This is the file we used to make sure News had pretty urls in TYPO3. Please note that the original and inspiration of this file is located here. And we made some small changes (removing the ID from the url) and used our own rootPageId and 404-error handling. Also remember to utilize the limitToPages array to select on which actual pages this config is applied.
rootPageId: 4
base: 'https://www.danielknows.com'
languages:
  -
    title: English
    enabled: true
    languageId: 0
    base: /
    typo3Language: default
    locale: en_US.UTF-8
    iso-639-1: en
    navigationTitle: English
    hreflang: en-us
    direction: ltr
    flag: us
errorHandling:
  -
    errorCode: '404'
    errorHandler: Page
    errorContentSource: 't3://page?uid=7'
routes: {  }
routeEnhancers:
  NewsPlugin:
    type: Extbase
    limitToPages: [2,3]
    extension: News
    plugin: Pi1
    routes:
      - { routePath: '{page}',_controller: 'News::list',_arguments: {'page': '@widget_0/currentPage'} }
      - { routePath: '{news_title}',_controller: 'News::detail',_arguments: {'news_title': 'news'} }      
    defaultController: 'News::list'    
    defaults:
      page: '0'
    requirements:
      page: '\d+'
    aspects:      
      news_title:
        type: PersistedPatternMapper
        tableName: 'tx_news_domain_model_news'
        routeFieldPattern: '^(?P.+)$'
        routeFieldResult: '{path_segment}'
      page:
        type: StaticRangeMapper
        start: '1'
        end: '200'
by Daniel at 2023-03-25T22:16:56.824Z
Copyright © DanielKnows.com 2019 - 2023 - Built with NuxtJS