Use Routing to rewrite URLs

This section will show you how you can rewrite the URLs for clubmanager detail views using Routing Enhancers and Aspects. TYPO3 Explained has an chapter Introduction to routing that you can read if you are not familiar with the concept yet. You will no longer need third party extensions like RealURL or CoolUri to rewrite and beautify your URLs.

How to rewrite URLs with clubmanager parameters

On setting up your page you should already have created a site configuration. You can do this in the backend module Site Managements > Sites.

Your site configuration will be stored in /config/sites/<your_identifier>/config.yaml. The following configurations have to be applied to this file.

Any URL parameters can be rewritten with the Routing Enhancers and Aspects. These are added manually in the config.yaml:

  1. Add a section routeEnhancers, if one does not already exist.
  2. Choose an unique identifier for your Routing Enhancer. It doesn't have to match any extension key.
  3. type: For clubmanager, the Extbase Plugin Enhancer (Extbase) is used.
  4. extension: the extension key, converted to UpperCamelCase.
  5. plugin: the plugin name of clubmanager could be city, member or location.
  6. After that you will configure individual routes and aspects depending on your use case.
/config/sites/<your_identifier>/config.yaml
routeEnhancers:
  ClubmanagerCity:
    type: Extbase
    extension: Clubmanager
    limitToPages:
      - /*YOUR PIDS HERE */
    plugin: City
    routes:
      -
        routePath: '/{city}'
        _controller: 'Cities::detail'
        _arguments:
          city: city
    aspects:
      city:
      type: SanitizeValue
      tableName: tx_clubmanager_domain_model_location
      columnName: city
  ClubmanagerMember:
    type: Extbase
    extension: Clubmanager
    limitToPages:
      - /*YOUR PIDS HERE */
    plugin: Member
    routes:
      -
        routePath: '/{ident}'
        _controller: 'Member::detail'
        _arguments:
          ident: member
    aspects:
      ident:
        type: PersistedAliasMapper
        tableName: tx_clubmanager_domain_model_member
        routeFieldName: ident
  ClubmanagerMemberList:
    type: Extbase
    extension: Clubmanager
    limitToPages:
      - /*YOUR PIDS HERE */
    plugin: MemberList
    routes:
      -
        routePath: '/page/{currentPage}'
        _controller: 'Member::list'
        _arguments:
          currentPage: currentPage
    defaultController: 'Member::list'
    defaults:
      currentPage: ''
    aspects:
      currentPage:
        type: StaticRangeMapper
        start: '1'
        end: '100'
  ClubmanagerLocation:
    type: Extbase
    extension: Clubmanager
    plugin: Location
    routes:
      -
        routePath: '/{location}'
        _controller: 'Location::detail'
        _arguments:
          location: location
    aspects:
      location:
        type: PersistedAliasMapper
        tableName: tx_clubmanager_domain_model_location
        routeFieldName: slug
  ClubmanagerLocationList:
    type: Extbase
    extension: Clubmanager
    plugin: LocationList
    routes:
      -
        routePath: '/page/{currentPage}'
        _controller: 'Location::list'
        _arguments:
          currentPage: currentPage
    defaultController: 'Location::list'
    defaults:
      currentPage: ''
    aspects:
      currentPage:
        type: StaticRangeMapper
        start: '1'
        end: '100'
Copied!

Using limitToPages

It is recommended to limit routeEnhancers to the pages where they are needed. This will speed up performance for building page routes of all other pages.

/config/sites/<your_identifier>/config.yaml
routeEnhancers:
  ClubmanagerCity:
    type: Extbase
    extension: Clubmanager
    limitToPages:
      - 20
      - 21
    plugin: City
    # routes and aspects will follow here
Copied!

About routes and aspects

In a nutshell:

  • routes will extend an existing route
    (means: your domain and page path) with arguments from GET parameters, like the following controller/action pair of the location detail view.
  • aspects can be used to modify these arguments.
    You could for example map the ident of the current member or the slug (or better: the optimized slug) of the current location. Different types of Mappers and Modifiers are available, depending on the case.
  1. URL of location detail page without routing:
https://www.example.com/location-list/location-detail/?tx_clubmanager_member[action]=detail&tx_clubmanager_member[controller]=Member&tx_clubmanager_member[location]=1&cHash=
Copied!
  1. URL of location detail page with routes:
https://www.example.com/location-list/location-detail/1/?cHash=
Copied!
  1. URL of location detail page with routes and aspects:
https://www.example.com/location-list/location-detail/firstname-lastname-company-city/
Copied!

The following example will only provide routing for the location list and detail view:

/config/sites/<your_identifier>/config.yaml
routeEnhancers:
  ClubmanagerLocation:
    type: Extbase
    extension: Clubmanager
    plugin: Location
    routes:
      - routePath: '/{location}'
        _controller: 'Location::detail'
        _arguments:
          location: location
    aspects:
      location:
        type: PersistedAliasMapper
        tableName: tx_clubmanager_domain_model_location
        routeFieldName: slug
Copied!

Please note the placeholder {location} in routeEnhancer ClubmanagerLocation:

  1. First, you assign the value of the location parameter (tx_clubmanager[location]) in _arguments.
  2. Next, in routePath you add it to the existing route.
  3. Last, you use aspects to map the slug of the given argument.

Both routes and aspects are only available within the current Routing Enhancer.

The names of placeholders are freely selectable.

Common routeEnhancer configurations

Basic setup (including Member, MemberList, Location, LocationList, Cities)

Prerequisites:

The plugins for member List View, member Detail View, location List View, location Detail View, cities List View and members per city List View are on separate pages.

Result:

  • Member Detail view: https://www.example.com/member-list/member-detail/ident/
  • Pagination: https://www.example.com/member-list/page/2/
  • Location Detail view: https://www.example.com/location-list/location-detail/firstname-lastname-company-city/
  • Pagination: https://www.example.com/location-list/page/2/
  • Members per city List view: https://www.example.com/cities-list/members-per-city/city/
/config/sites/<your_identifier>/config.yaml
routeEnhancers:
  ClubmanagerCity:
    type: Extbase
    extension: Clubmanager
    limitToPages:
      - 90
      - 91
    plugin: City
    routes:
      -
        routePath: '/{city}'
        _controller: 'Cities::detail'
        _arguments:
          city: city
    aspects:
      city:
        type: SanitizeValue
        tableName: tx_clubmanager_domain_model_location
        columnName: city
  ClubmanagerMember:
    type: Extbase
    extension: Clubmanager
    plugin: Member
    routes:
      -
        routePath: '/{ident}'
        _controller: 'Member::detail'
        _arguments:
          ident: location
    aspects:
      ident:
        type: PersistedAliasMapper
        tableName: tx_clubmanager_domain_model_member
        routeFieldName: ident
  ClubmanagerMemberList:
    type: Extbase
    extension: Clubmanager
    plugin: MemberList
    routes:
      -
        routePath: '/page/{currentPage}'
        _controller: 'Member::list'
        _arguments:
          currentPage: currentPage
    defaultController: 'Member::list'
    defaults:
      currentPage: ''
    aspects:
      currentPage:
        type: StaticRangeMapper
        start: '1'
        end: '100'
  ClubmanagerLocation:
    type: Extbase
    extension: Clubmanager
    plugin: Location
    routes:
      - routePath: '/{location}'
        _controller: 'Location::detail'
        _arguments:
          location: location
    aspects:
      location:
        type: PersistedAliasMapper
        tableName: tx_clubmanager_domain_model_location
        routeFieldName: slug
  ClubmanagerLocationList:
    type: Extbase
    extension: Clubmanager
    plugin: LocationList
    routes:
      -
        routePath: '/page/{currentPage}'
        _controller: 'Location::list'
        _arguments:
          currentPage: currentPage
    defaultController: 'Location::list'
    defaults:
       currentPage: ''
    aspects:
       currentPage:
        type: StaticRangeMapper
        start: '1'
        end: '100'
Copied!

Localized pagination

Not done yet