Typo3 9 路由配置生成 404 错误

Typo3 9 Routing config generating 404 error

我们有一个 Typo3 9 服务器,上面有许多网站 运行。我们还有新闻插件,方便添加博文。

在 Typo3 9 中,旧的 RealURL 系统已被弃用,取而代之的是内置系统。这适用于普通页面,但不适用于新闻文章。

我们已经实现了以下 YAML confic 文件,该文件基于新闻插件和许多其他堆栈溢出帖子提供的示例。问题是虽然我们可以确认配置已加载,但我们收到 404 错误:

404 Page not found!

Reason: The requested page does not exist

Current URL: /blog/2020-january/

然后我们开始深入,逐行检查代码以了解问题所在。我们确实设法呈现 /blog/2020-january/ 页面,但它没有内容。 None 个博客页面解决了其中一个问题。

我们是否应该寻找其他配置来启用此功能?我们已经让另一个 Typo3 人查看了这个问题,但没有成功。

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
Please check your code see below code of news_title

routeEnhancers: News: type: Extbase extension: News plugin: Pi1 routes: - routePath: '/{news-title}' _controller: 'News::detail' _arguments: news-title: 新闻方面:news-title:类型:PersistedAliasMapper 表名:tx_news_domain_model_news routeFieldName:path_segment

从 path_segment 中删除大括号,按照上面的方法或在文档中删除,谢谢

请看官方文档https://docs.typo3.org/p/georgringer/news/7.2/en-us/AdministratorManual/BestPractice/Routing/Index.html

经过努力,我们取得了成功。

首先,最终的工作配置:

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

重要的事情:

  • 分页路径包含页面前缀。它在哪个页面上没有歧义。
  • 没有尾部斜杠,此外,文章在路径段中也不能有尾部斜杠。这可以在数据库中完成并在
  • 之后清除缓存
  • 无默认值
  • 不同的月份映射是由于需要匹配现有系统

我们从 9.5.15 升级到 9.5.18。不清楚是否需要这样做。

在站点包中,包含默认的 TypoScript 模板 link.skipControllerAndAction = 1。这需要删除以在列表视图中显示文章的友好 url。 (参见 How to properly set url-routing for tx-news in TYPO3 9.5.5?

最后,要使日期、标签和类别过滤器起作用,必须取消选中列表->插件->附加中的禁用覆盖需求。