XML based frontend routing for Symphony.
By default, the extension stores a routes.xml
file in your workspace folder.
However, a new setting is also added to your config.php
, where you can provide an alternative file path relative to the workspace folder.
This extension completely replaces Symphony's default routing.
This means it will throw a FrontendPageNotFoundException and display a 404 page for every path that's not defined in your routes.xml
file, even if the page actually exists.
For better performance, the routes.xml
file is only processed once and then cached using Symphony's Cacheable API.
It's therefore necessary to refresh the cache after making changes in your routes.xml
or config.php
.
This can be done by simply re-enabling the extension under System › Extensions
.
The routes.xml
schema is pretty simple.
<routes>
<route from="..." to="..." />
<route from="..." to="...">
<filter parameter="..." match="..." />
</route>
</routes>
Each route is defined by a <route>
element, which has two attributes, @from
and @to
.
These attributes contain pathes relative to your root URL.
<route from="/en/about-us/" to="/about-us/" />
<route from="/de/ueber-uns/" to="/about-us/" />
The @from
path, which your users see in their browser address bar, is silently routed to an existing page path.
Parameters are declared by a leading :
and can be reused in the @to
path.
<route from="/:language/blog/:article/" to="/blog/:article/" />
To match a parameter against a specific pattern, you can optionally provide a <filter>
element for that parameter inside the <route>
element.
A <filter>
element also has two attributes, @parameter
and @match
.
<route from="/:language/blog/:article/" to="/blog/:article/">
<filter parameter=":language" match="[a-z]{2}" />
</route>
The @match
attribute can contain a PCRE regex pattern.
By default, all parameters will be matched against the [\w\.-]+
pattern.