retour-for-kirby
retour-for-kirby copied to clipboard
Feature Request: Handle multiple URLs
Kirby can be configured to use multiple URLs. It would be awesome for Retour to be able to use multiple URLs/hostnames for redirects.
E.g. I'd love to be able to create redirects like this: a.com -> blog/post-a
and b.com -> blog/post-b
Obviously this should be optional/only available when there are actually multiples URLs configured.
@pReya can't promise anything but trying to understand your feature request better:
You mean when using https://getkirby.com/docs/reference/system/options/url to set up your site being reachable by different URLs? And then you want to only redirect someone accessing a.com/foo
to e.g. a.com/blog
but b.com/foo
to b.com/projects
?
Correct. It would be nice if the URLs are completely independent and can be configured however one sees fit (either pointing them to the same location or to different locations).
This could be tricky: I think for Kirby's router in this case, the request to a.com/foo
and b.com/foo
would look exactly the same
This could be tricky: I think for Kirby's router in this case, the request to
a.com/foo
andb.com/foo
would look exactly the same
I've built this functionality by using $kirby->environment()->host()
, which seems to always contain the URL from the host header.
Does Kirby's default router use that in any way? Retour is built on top of the default router, so if I can tell the router in any way that a specific route is only meant for one host, that would work. Otherwise, this will be hard to implement as I am not too keen to reimplement the router functionality.
I'm not sure I understand the problem/question, sorry. You can access the global $kirby->environment()->host()
from within any action
inside of the Kirby routes array.
From what I understand/quickly read in the code: Retour basically returns arrays of Redirects to the Kirby router.
Kirby does not include the configured url
in the matched pattern
in the router – it will always match for ALL configured URLs. So, a route with pattern => 'example'
will match both: a.com/example
AND b.com/example
. So inside of this route action, there needs to be another conditional logic, to see which host was requested, and then it can return the proper Redirect, according to the selected setting from the Admin panel/data file.