route增强不存在的新闻URL

时间:2019-05-11 07:57:46

标签: typo3 tx-news typo3-9.x

我为新闻配置了routeEnhancers,似乎一切正常。我的网址看起来对用户友好,domain.my / news / details / something-new-242。现在,我想检查当有人在我的网址中添加一些字符时会发生什么情况。my/ news / details / something-new-242-2ddwdwedw

typo3引发错误:路线“ tx_news_pi1_0”的参数“ acec1fc0ac7e1adfbcd522115dc07925”必须与“ [^ /] ++”(给出的“”)匹配,以生成相应的URL。

我期望的是404错误页面。

我的问题是如何修改routeEnhancers以抛出404

routeEnhancers:

  NewsPlugin:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      - { routePath: '/{news_post}', _controller: 'News::detail', _arguments: {'news_post': 'news'} }
      - { routePath: '/{tag_name}', _controller: 'News::list', _arguments: {'tag_name': 'overwriteDemand/tags'} }
      - { routePath: '/{category}', _controller: 'News::list', _arguments: {'category': 'overwriteDemand/categories'} }
      - { routePath: '/{page}', _controller: 'News::list', _arguments: {'page': '@widget_0/currentPage'} }
      - { routePath: '/{year}/{month}', _controller: 'News::list', _arguments: {'year': 'overwriteDemand/year', 'month': 'overwriteDemand/month' } }
      - { routePath: '/{year}/{month}/{day}', _controller: 'News::list', _arguments: {'year': 'overwriteDemand/year', 'month': 'overwriteDemand/month', 'day': 'overwriteDemand/day' } }
    defaultController: 'News::list'
    aspects:
      news_post:
        type: PersistedPatternMapper
        tableName: 'tx_news_domain_model_news'
        routeFieldPattern: '^(?P<path_segment>.+)-(?P<uid>\d+)$'
        routeFieldResult: '{path_segment}-{uid}'
      tag_name:
        type: PersistedAliasMapper
        tableName: 'tx_news_domain_model_tag'
        routeFieldName: 'slug'
      category:
        type: PersistedAliasMapper
        tableName: 'sys_category'
        routeFieldName: 'slug'
      page:
        type: StaticRangeMapper
        start: '1'
        end: '1000'

1 个答案:

答案 0 :(得分:0)

您还错过了404重定向配置,请尝试一下

routeEnhancers:

  NewsPlugin:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      - { routePath: '/{news_post}', _controller: 'News::detail', _arguments: {'news_post': 'news'} }
      - { routePath: '/{tag_name}', _controller: 'News::list', _arguments: {'tag_name': 'overwriteDemand/tags'} }
      - { routePath: '/{category}', _controller: 'News::list', _arguments: {'category': 'overwriteDemand/categories'} }
      - { routePath: '/{page}', _controller: 'News::list', _arguments: {'page': '@widget_0/currentPage'} }
      - { routePath: '/{year}/{month}', _controller: 'News::list', _arguments: {'year': 'overwriteDemand/year', 'month': 'overwriteDemand/month' } }
      - { routePath: '/{year}/{month}/{day}', _controller: 'News::list', _arguments: {'year': 'overwriteDemand/year', 'month': 'overwriteDemand/month', 'day': 'overwriteDemand/day' } }
    defaultController: 'News::list'
    aspects:
      news_post:
        type: PersistedPatternMapper
        tableName: 'tx_news_domain_model_news'
        routeFieldPattern: '^(?P<path_segment>.+)-(?P<uid>\d+)$'
        routeFieldResult: '{path_segment}-{uid}'
      tag_name:
        type: PersistedAliasMapper
        tableName: 'tx_news_domain_model_tag'
        routeFieldName: 'slug'
      category:
        type: PersistedAliasMapper
        tableName: 'sys_category'
        routeFieldName: 'slug'
      page:
        type: StaticRangeMapper
        start: '1'
        end: '1000'

errorHandling:
  -
    errorCode: '404'
    errorHandler: Page
    errorContentSource: 't3://page?uid=14'

我想这就是你想要的,不是吗?