Plugin URL hook

is it possible to listen for an url with a plugin/theme?
For example, I want to create an .ics file download and generate the files on the fly via php. I first placed an .php file in the main plugin directory, but couldn’t access it via an url, which is great for security reasons!
But how can I achieve, that if for example the url htttps://website.tld/calender?item=123 whould result in a call of my plugin function which creates the downloadable file?
Best regards

I believe a sitemap plugin can be as an example for what you’re looking for

/** @var Uri $uri */
$uri = $this->grav['uri'];
$route = $this->config->get('plugins.sitemap.route');

if ($route && $route == $uri->path()) {
    // Do your things


I first placed an .php file in the main plugin directory

This smells like a lack of insight in the concepts of plugins. You might want to take a look at the docs on plugins first to get a general idea of the concepts of plugins.

Then, using $ bin/plugin devtools new-plugin you can create a skeleton plugin in which you can give the code provided by @Karmalakas a try.

To get the query params have a look at the API in the docs: Uri::query()