Hi!
I’m working on a website that has a calendar for events. I set up a custom route that gives me back the requested month like so:
'routes' => [
[
'pattern' => 'events/calendar/(:all)',
'action' => function ($month) {
$data = [
'month' => $month,
];
return page('events')->render($data);
}
]
],
This works well for the pattern that I use which is "y-m" => "23-04"
. But now I also want the events page to redirect automatically to current month. So when I go to /events
it should take me to /events/calendar/23-04
$currentMonth = date('y-m');
$subpage = "/events/calendar/" . $currentMonth . "/";
header('Location: ' . $subpage);
die();
I tried it like that but I think it gives me an infinite loop, since chrome is telling me that localhost redicted me too many times:
ERR_TOO_MANY_REDIRECTS
How can I fix it? Also, if there is a better way to do this, please tell me.
Thank you for your help!