grav
grav copied to clipboard
Redirect regex pattern to match entire $source_url
Problem The regex checking for redirects defined in site.yaml, allows and passes on just a part of the path.
Example site.yaml
redirects:
/this-is-my-url: '/somepath'
/this-is-sparta: '/some-other-path'
/this: '/some-different-path'
With this configuration, when hitting /this, I would get redirected to /somepath because it matches on the first redirects entry.
This happens because the current regex only checks start of string until found:
#^\/this#
Adding an end of string check in the regex, will not match on the first two redirects, but continue on until it matches on the last entry:
#^\/this$#
What about /this/is/my/new/path
, it should redirect to /some-different-path/is/my/new/path
Could we have this as a config toggle though? Developers inherit sites to migrate to Grav that have all kinds of crazy URL systems. I am doing one now where having such a toggle would allow me to put in a full set of redirects. Without this, I can't see a way to make them all work :/
Instead of implementing the patch and breaking all redirects, you can do this instead:
redirects:
'/this-is-my-url$': '/somepath'
'/this-is-sparta$': '/some-other-path'
'/this$': '/some-different-path'