Search code examples
typo3typo3-extensions

Typo3 9 Routing config generating 404 error


We have a Typo3 9 server with a number of websites running on it. We also have the news plugin to facilitate the addition of blog posts.

With Typo3 9 the old RealURL system has been depricated in favour of a built in system. This is working for the normal pages but is not working for the news articles.

We have implemented the following YAML confic file which is based off the examples provided by the news plugin and a number of other stack overflow posts. The problem is that while we can confirm that the config is loaded, we get a 404 error:

404 Page not found!

Reason: The requested page does not exist

Current URL: /blog/2020-january/

We then commenced in depth, line by line examinantion of the code to understand what is going wrong. We did manage to render the /blog/2020-january/ page, but it had no content. None of the individual blog pages resolve either.

Are there other configurations that we should look for to enable this functionality? We have had another Typo3 person look at the problem without success.

rootPageId: 156
base: 'https://example.site'
baseVariants: {  }
languages:
  -
    title: English
    enabled: true
    languageId: '0'
    base: /
    typo3Language: default
    locale: en_AU
    iso-639-1: en
    navigationTitle: ''
    hreflang: ''
    direction: ''
    flag: au
errorHandling: {  }
routes: {  }
routeEnhancers:
    PageTypeSuffix:
      type: PageType
      default: '/'
      index: '/'
      map:
        '/': 0
    NewsPlugin:
        type: Extbase
        extension: News
        plugin: Pi1
        limitToPages:
          - 187
          - 201
        routes:
          # Detail view:
          - routePath: '/{news_title}'
            _controller: 'News::detail'
            _arguments: {'news_title': 'news'}
          # Categories:
          - routePath: '/{category}'
            _controller: 'News::list'
            _arguments: {'category': 'overwriteDemand/categories'}
          # Tags:
          - routePath: '/{tag_name}'
            _controller: 'News::list'
            _arguments: {'tag_name': 'overwriteDemand/tags'}
          # Pagination:
          - routePath: '/{page}'
            _controller: 'News::list'
            _arguments: {'page': '@widget_0/currentPage'}
          # Archive:
          - routePath: '/{localized_archive}/{year}/{month}'
            _controller: 'News::archive'
          # Date:
          - routePath: '/{year}-{month}'
            _controller: 'News::list'
            _arguments:
              year: overwriteDemand/year
              month: overwriteDemand/month
        defaultController: 'News::list'
        defaults:
            page: '0'
            year: ''
            month: ''
        requirements:
            page: '\d+'
            news_title: '^[a-zA-Z0-9].*$'
        aspects:
            page:
                type: StaticRangeMapper
                start: '1'
                end: '100'
            news_title:
                type: PersistedPatternMapper
                tableName: tx_news_domain_model_news
                routeFieldPattern: '^(?P<path_segment>.+)$'
                routeFieldResult: '{path_segment}'
            category:
                type: PersistedAliasMapper
                tableName: 'sys_category'
                routeFieldName: 'title'
            tag_name:
                type: PersistedAliasMapper
                tableName: 'tx_news_domain_model_tag'
                routeFieldName: 'title'
            localized_archive:
                type: LocaleModifier
                default: 'archive'
                routeFieldName: 'title'
                localeMap:
                  - languageId: 'de_.*'
                    value: 'archiv'
                  - languageId: 'fr_.*'
                    value: 'archives'
            year:
                type: StaticRangeMapper
                start: '1970'
                end: '2099'
            month:
                type: StaticValueMapper
                map:
                  january: '01'
                  february: '02'
                  march: '03'
                  april: '04'
                  may: '05'
                  june: '06'
                  july: '07'
                  august: '08'
                  september: '09'
                  october: 10
                  november: 11
                  december: 12

Solution

  • After a lot of effort we have success.

    Firstly, the final working config:

    routeEnhancers:
      NewsPlugin:
        type: Extbase
        extension: News
        plugin: Pi1
        limitToPages:
          - 201
          - 187
        routes:
          -
            routePath: '/{news_title}'
            _controller: 'News::detail'
            _arguments:
              news_title: news
          -
            routePath: '/{category}'
            _controller: 'News::list'
            _arguments:
              category: overwriteDemand/categories
          -
            routePath: '/{tag_name}'
            _controller: 'News::list'
            _arguments:
              tag_name: overwriteDemand/tags
          -
            routePath: '/page-{page}'
            _controller: 'News::list'
            _arguments:
              page: '@widget_0/currentPage'
          -
            routePath: '/{year}/{month}'
            _controller: 'News::list'
            _arguments:
              year: overwriteDemand/year
              month: overwriteDemand/month
        defaultController: 'News::list'
    #    defaults:
    #      page: '0'
    #      year: ''
    #      month: ''
        requirements:
          page: \d+
    #      news_title: '^[a-zA-Z0-9].*$'
        aspects:
          page:
            type: StaticRangeMapper
            start: '1'
            end: '100'
          news_title:
            type: PersistedAliasMapper
            tableName: tx_news_domain_model_news
            routeFieldName: path_segment
          category:
            type: PersistedAliasMapper
            tableName: sys_category
            routeFieldName: title
          tag_name:
            type: PersistedAliasMapper
            tableName: tx_news_domain_model_tag
            routeFieldName: title
          year:
            type: StaticRangeMapper
            start: '1970'
            end: '2099'
          month:
            type: StaticRangeMapper
            start: '01'
            end: '12'
          #month:
          #  type: StaticValueMapper
          #  map:
          #    january: '01'
          #    february: '02'
          #    march: '03'
          #    april: '04'
          #    may: '05'
          #    june: '06'
          #    july: '07'
          #    august: '08'
          #    september: '09'
          #    october: 10
          #    november: 11
          #    december: 12
    

    The important things:

    • The pagination path includes the page prefix. There is no ambiguity about what page it is on.
    • No trailing slashes, additionally, the articles also can't have trailing slashes in the path segment. This can be done in the database and clearing the cache after
    • No defaults
    • The different month mapping is due to a requirement to match an existing system

    We upgraded from 9.5.15 to 9.5.18. It is not clear if this was required.

    In the site package, the default TypoScript template included link.skipControllerAndAction = 1. This needs to be removed to show the friendly urls for the articles in the list view. (See How to properly set url-routing for tx-news in TYPO3 9.5.5?)

    Finally, for the date, tag and category filters to work, Disable override demand in List->Plugin->Additional must be unticked. overwrite demand