Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Handle multiple URLs #323

Open
pReya opened this issue Sep 3, 2023 · 6 comments
Open

Feature Request: Handle multiple URLs #323

pReya opened this issue Sep 3, 2023 · 6 comments
Labels
feature ⭐️ New feature or request

Comments

@pReya
Copy link

pReya commented Sep 3, 2023

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.

@distantnative distantnative added the feature ⭐️ New feature or request label Sep 3, 2023
@distantnative
Copy link
Owner

@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?

@pReya
Copy link
Author

pReya commented Oct 29, 2023

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).

@distantnative
Copy link
Owner

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

@pReya
Copy link
Author

pReya commented Oct 29, 2023

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

I've built this functionality by using $kirby->environment()->host(), which seems to always contain the URL from the host header.

@distantnative
Copy link
Owner

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.

@pReya
Copy link
Author

pReya commented Oct 29, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⭐️ New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants