Use Routing to rewrite URLs

This section will show you how you can rewrite the URLs for tt_address using Routing Enhancers and Aspects. TYPO3 Explained has a 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 address 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 tt_address, the Extbase Plugin Enhancer (Extbase) is used.

  4. extension: the extension key, converted to UpperCamelCase.

  5. plugin: the plugin name of address is ListView, even for the detail page.

  6. After that you will configure individual routes and aspects depending on your use case.

/config/sites/<your_identifier>/config.yaml
 1Address:
 2 type: Extbase
 3 limitToPages:
 4   - 8
 5   - 10
 6   - 11
 7 extension: TtAddress
 8 plugin: ListView
 9 routes:
10   - routePath: '/{address-title}'
11     _controller: 'Address::show'
12     _arguments:
13       address-title: address
14   - routePath: '/{page-label}-{page}'
15     _controller: 'Address::list'
16     _arguments:
17       page: 'currentPage'
18 defaultController: 'Address::list'
19 aspects:
20   address-title:
21     type: PersistedAliasMapper
22     tableName: tt_address
23     routeFieldName: slug
24   page:
25     type: StaticRangeMapper
26     start: '1'
27     end: '100'
28   page-label:
29     type: LocaleModifier
30     default: seite
31     localeMap:
32       - locale: 'en_.*'
33         value: page
34       - locale: 'it_.*'
35         value: pagina
36       - locale: 'fr_.*'
37         value: page
38       - locale: 'es_.*'
39         value: pagina

Tip

If your routing does not work as expected, check the indentation of your configuration blocks. Proper indentation is crucial in YAML.

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.