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
 1routeEnhancers:
 2  ClubmanagerCity:
 3    type: Extbase
 4    extension: Clubmanager
 5    limitToPages:
 6      - /*YOUR PIDS HERE */
 7    plugin: City
 8    routes:
 9      -
10        routePath: '/{city}'
11        _controller: 'Cities::detail'
12        _arguments:
13          city: city
14    aspects:
15      city:
16      type: SanitizeValue
17      tableName: tx_clubmanager_domain_model_location
18      columnName: city
19  ClubmanagerMember:
20    type: Extbase
21    extension: Clubmanager
22    limitToPages:
23      - /*YOUR PIDS HERE */
24    plugin: Member
25    routes:
26      -
27        routePath: '/{ident}'
28        _controller: 'Member::detail'
29        _arguments:
30          ident: member
31    aspects:
32      ident:
33        type: PersistedAliasMapper
34        tableName: tx_clubmanager_domain_model_member
35        routeFieldName: ident
36  ClubmanagerMemberList:
37    type: Extbase
38    extension: Clubmanager
39    limitToPages:
40      - /*YOUR PIDS HERE */
41    plugin: MemberList
42    routes:
43      -
44        routePath: '/page/{currentPage}'
45        _controller: 'Member::list'
46        _arguments:
47          currentPage: currentPage
48    defaultController: 'Member::list'
49    defaults:
50      currentPage: ''
51    aspects:
52      currentPage:
53        type: StaticRangeMapper
54        start: '1'
55        end: '100'
56  ClubmanagerLocation:
57    type: Extbase
58    extension: Clubmanager
59    plugin: Location
60    routes:
61      -
62        routePath: '/{location}'
63        _controller: 'Location::detail'
64        _arguments:
65          location: location
66    aspects:
67      location:
68        type: PersistedAliasMapper
69        tableName: tx_clubmanager_domain_model_location
70        routeFieldName: slug
71  ClubmanagerLocationList:
72    type: Extbase
73    extension: Clubmanager
74    plugin: LocationList
75    routes:
76      -
77        routePath: '/page/{currentPage}'
78        _controller: 'Location::list'
79        _arguments:
80          currentPage: currentPage
81    defaultController: 'Location::list'
82    defaults:
83      currentPage: ''
84    aspects:
85      currentPage:
86        type: StaticRangeMapper
87        start: '1'
88        end: '100'

Tip

If your routing doesn't work as expected, check the indentation of your configuration blocks. Proper indentation is crucial in YAML.

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
1routeEnhancers:
2  ClubmanagerCity:
3    type: Extbase
4    extension: Clubmanager
5    limitToPages:
6      - 20
7      - 21
8    plugin: City
9    # routes and aspects will follow here

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=
  1. URL of location detail page with routes:

https://www.example.com/location-list/location-detail/1/?cHash=
  1. URL of location detail page with routes and aspects:

https://www.example.com/location-list/location-detail/firstname-lastname-company-city/

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

/config/sites/<your_identifier>/config.yaml
 1routeEnhancers:
 2  ClubmanagerLocation:
 3    type: Extbase
 4    extension: Clubmanager
 5    plugin: Location
 6    routes:
 7      - routePath: '/{location}'
 8        _controller: 'Location::detail'
 9        _arguments:
10          location: location
11    aspects:
12      location:
13        type: PersistedAliasMapper
14        tableName: tx_clubmanager_domain_model_location
15        routeFieldName: slug

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
 1routeEnhancers:
 2  ClubmanagerCity:
 3    type: Extbase
 4    extension: Clubmanager
 5    limitToPages:
 6      - 90
 7      - 91
 8    plugin: City
 9    routes:
10      -
11        routePath: '/{city}'
12        _controller: 'Cities::detail'
13        _arguments:
14          city: city
15    aspects:
16      city:
17        type: SanitizeValue
18        tableName: tx_clubmanager_domain_model_location
19        columnName: city
20  ClubmanagerMember:
21    type: Extbase
22    extension: Clubmanager
23    plugin: Member
24    routes:
25      -
26        routePath: '/{ident}'
27        _controller: 'Member::detail'
28        _arguments:
29          ident: location
30    aspects:
31      ident:
32        type: PersistedAliasMapper
33        tableName: tx_clubmanager_domain_model_member
34        routeFieldName: ident
35  ClubmanagerMemberList:
36    type: Extbase
37    extension: Clubmanager
38    plugin: MemberList
39    routes:
40      -
41        routePath: '/page/{currentPage}'
42        _controller: 'Member::list'
43        _arguments:
44          currentPage: currentPage
45    defaultController: 'Member::list'
46    defaults:
47      currentPage: ''
48    aspects:
49      currentPage:
50        type: StaticRangeMapper
51        start: '1'
52        end: '100'
53  ClubmanagerLocation:
54    type: Extbase
55    extension: Clubmanager
56    plugin: Location
57    routes:
58      - routePath: '/{location}'
59        _controller: 'Location::detail'
60        _arguments:
61          location: location
62    aspects:
63      location:
64        type: PersistedAliasMapper
65        tableName: tx_clubmanager_domain_model_location
66        routeFieldName: slug
67  ClubmanagerLocationList:
68    type: Extbase
69    extension: Clubmanager
70    plugin: LocationList
71    routes:
72      -
73        routePath: '/page/{currentPage}'
74        _controller: 'Location::list'
75        _arguments:
76          currentPage: currentPage
77    defaultController: 'Location::list'
78    defaults:
79       currentPage: ''
80    aspects:
81       currentPage:
82        type: StaticRangeMapper
83        start: '1'
84        end: '100'

Localized pagination

Not done yet