Managing redirection rules is a common requirement for web applications, especially in cases where you do not want to lose incoming links that have changed or been removed over time.
You can manage redirection rules on your Platform.sh projects in two different ways, which we describe here. If neither of these options satisfy your redirection needs, you can still implement redirects directly from within your application, which if implemented with the appropriate caching headers would be almost as efficient as using the configuration options provided by Platform.sh.
Whole-route redirects
Using whole-route redirects, you can define very basic routes in your .platform/routes.yaml
file whose sole purpose is to redirect. A typical use case for this type of route is adding or removing a www.
prefix to your domain, as the following example shows:
https://{default}/:
type: redirect
to: https://www.{default}/
Partial redirects
In the .platform/routes.yaml
file you can also add partial redirect rules to existing routes:
https://{default}/:
# ...
redirects:
expires: 1d
paths:
'/from':
to: 'https://example.com/'
'^/foo/(.*)/bar':
to: 'https://example.com/$1'
regexp: true
For more information about redirects, please visit our public documentation on this topic.