Authors:
This module provides a system for users to configure arbitrary redirections in the CMS. These can be used for legacy redirections, friendly URLs, and anything else that involves redirecting one URL to another.
The URLs may include query-strings, and can be imported from a CSV using the "Redirects" model admin included.
The redirection is implemented as a plug-in to the 404 handler, which means that you can't create a redirection for a page that already exists on the site.
^8.1
^5
Legacy:
^4
: ^2
tags^3
: ^1
tags composer require silverstripe/redirectedurls
For example, to redirect "/about-us/index.html?item=1" to "/about-us/item/1", set:
From Base: /about-us/index.html
From Querystring: item=1
To: /about-us/item/1
CSV Importer, example file format:
FromBase, FromQuerystring, To
/about-us/index.html, item=1, /about/item/1
/example/no-querystring.html, ,/example/no-querystring/
/example/two-queryparams.html, foo=1&bar=2, /example/foo/1/bar/2
/about/*, ,/about-us
This assumes that your project as silverstripe/assets
.
Please note: By default, many web services will route assets (and other resources) directly through Nginx. If this is the case for you, then please be aware that adding the following extension will not be enough to enable this functionality.
---
Name: app-redirectedurls
---
SilverStripe\Assets\Flysystem\FlysystemAssetStore:
extensions:
- SilverStripe\RedirectedURLs\Extension\AssetStoreURLHandler
This might differ for your web service, but you can use the following for any service that respect the .platform.yml
configuration, and you can use this if you are using the latest Silverstripe dev-boxes
.
Be very aware that Apache is slower than Nginx for serving static resources. Making this change could mean a significant impact to your application's performance.
URL rules allow you to customise default behaviour:
url_rules:
mysite:
- '<regex>': '<rule>'
The regex must be in a format accepted by nginx. This will be used as a case-insensitive location matcher and is compared against the full URL.
^/assets/
- match all URLs pointing to the assets directory\.(gif|jpg|jpeg)$
- match extensions at the end of the URLFor example, if you wanted to route all assets through Apache.
platform.yml
:
url_rules:
mysite:
- '^/assets/': 'apache'
Instead of serving all assets, is there are specific extension (or extensions) that you could call out? EG, is it only PDFs that you want to support redirect for?
url_rules:
mysite:
- '^/assets/.+\.(pdf)$': 'apache'
Or what about only serving a specific asset directory that you've specified with your content authors?
url_rules:
mysite:
- '^/assets/Documents/': 'apache'