The current release is 2.2.7
A module for SilverStripe which will allow both simple and regular expression link redirections based on customisable mappings, either hooking into a page not found or replacing the default automated URL handling.
This is based upon the existing link mapping module, aiming to provide a more robust solution for both users and developers alike, with further support and customisation!
- SilverStripe 3.1.X or 3.2.X
This module does not require the CMS.
- Place the module under your root project directory.
/dev/build
- Select
Misdirection
through the CMS. - Create a link mapping.
/mapping
These allow both simple and regular expression link redirections, and can be used for legacy page redirection, vanity URLs (more below), or redirection based on specific URL patterns.
The link mapping with the highest priority (followed by greatest specificity) will be used, and replaces the default automated URL handling out of the box. This default behaviour may be configured to only hook into a page not found:
MisdirectionRequestFilter:
enforce_misdirection: false
When there are multiple matches, the link mapping first created will be used. This default behaviour may be configured to prioritise the link mapping most recently created:
LinkMapping:
priority: 'DESC'
While it is possible to create these manually (as above), a content author may directly create a link mapping from a page. However, it should be noted that these are instantiated with a low priority of 2
, and therefore other link mappings with higher priority will take precedence.
When a user happens to encounter a page not found, a specified rule may be triggered to prevent displaying this. It is possible for an administrator to configure a global fallback through the site configuration, however a specific page setting will take precedence.
- Select
Settings
- Select
Pages
The link mappings are processed server side to prevent inefficient and problematic mappings, using a request filter.
When you want to see exactly what is happening behind the scenes for a given URL, the model admin provides a powerful testing interface!
Once a maximum number of requests has been reached, the server will respond with a page not found. The following is the default configuration:
MisdirectionRequestFilter:
maximum_requests: 9
It is possible to bypass the request filter completely by appending ?misdirected=1
to the URL. This is fantastic for debugging, however does not apply to the testing interface for obvious reasons.
This may be completely replaced, in which case legacy URLs will no longer resolve based on page version history.
MisdirectionRequestFilter:
replace_default: true
When a page is moved, the appropriate link mappings are automatically created and maintained. This allows full control over which legacy URLs remain in the system.
To ensure the current page version history remains, /dev/tasks/MisdirectionHistoricalLinkMappingsTask
may be used to instantiate the appropriate link mappings. However, this task is currently only supported by MySQL
.
Nathan Glasl, [email protected]