Is this even possible if I have many (thousands) of redirects since they would be stored in an environment variable?
Yes, redirect routes still show in in the PLATFORM_ROUTES environment variable. That means it is possible that having too many redirects will run into the environment variable length limit.
If you need a large number of redirects, there are two ways to reduce that overhead:
-
Use regular-expression-based redirects. If your redirects have common patterns they can usually be collapsed into a small number of regular-expression-based rules.
-
Handle redirects in your application. Your application will always have more knowledge of what redirects are needed and when than a statically configured rule in
routes.yaml
. If you have a large or complex redirect ruleset, it is almost always better to handle that logic in proper application code rather than the routes configuration. Most applications and frameworks have built-in redirect handling mechanisms that you can leverage. Consult their documentation as appropriate.