Adding parameters to page URL depending on usergroup

If I used this to have 2 different usergroups how could I modify the URL of the users pages so that usergroup A would get a URL like “website.test/landingpage?group=a” and usergroup B would get “website.test/landingpage?group=b”? Is this possible at all?

The example code in the recipe doesn’t make use of URLs at all. Of course you can display different content based on on URL parameters, but the question is how would you define which visitor group gets which link?

Well im not interested in displaying different content based on the parameter in the URL.
But rather modifying the URL based on which usergroup the user belongs to.

The different content management is done via: already

<?php if (visitorgroup('a') === true) : ?>
   Some content for visitors in group a
<?php else: ?>
   Some content for visitors in group b
<?php endif ?>

I guess what you mean is that I could just modify every Link across the whole website to have these parameters in them. I guess that would work but is rather much work.

You should be able to do that via a route, i.e. inside the route for the page, check the visitorgroup and redirect with that parameter attached.

Alright but using this: how can I attach an parameter then? This would just display the page without a new parameter in the URL.

I guess I could use something like this:

return go('landingpage?group=A');

But that will just result in a loop of redirects and no page contents beeing displayed even if there was no loop, is there a way to use and just add a parameter with something like:?

return page('landingpage')->parameter("group", "A");

You can use like that:

go(page('landingpage')->url() . '?group=A&foo=bar', 301);

Also we have such an idea right now and you can upvote:

But when using a solution like that I find myself having the problem that my route and redirect will just loop in itself and a “ERR_TOO_MANY_REDIRECTS” will be thrown. I Somehow have to filter that the redirect will only be triggered once, and I simply cannot find out how I would go about that.

'routes' => [
        'pattern' => 'category/landingpage',
        'action'  => function () {
            go(page('category/landingpage')->url() . '?group=A&foo=bar', 301);

Ah, alright, that is because the pattern ignores parameters. Maybe you can solve it by redirecting to a different URL instead


Which are then handled by corresponding routes.

I guess thats how I will have to do it, even when I would have prefered the parameter way, thanks for the help.