@nicolasG Grav's routing capabilities are quite flexibel and powerful. Have a look at the documentation for Routing.
For instance you can set multiple aliases in the frontmatter of a page. For example the page mydomain/ads/maison-a-rouen with the following frontmatter...
routes:
aliases:
- /api/1
- /api/maison/1
... can be accessed using the urls mydomain/ads/maison-a-rouen, mydomain/api/1 and mydomain/api/maison/1. These aliases can be set using the Admin tool, or via any editor in the page's *.md file.
In your plugin you can test for the requested url and if the url matches, it can send back the required data.
These aliases can also be generated when saving/updating a page using Admin, for instance if you want to assign unique ids to the ads. When adding a onAdminSave method in your plugin, your could do sometime like:
public function onPluginsInitialized()
{
// Don't proceed if we are not in the admin plugin
if (!$this->isAdmin()) {
return;
}
// Only proceed if page is child of "ads"
$paths = $this->grav['uri']->paths();
if (count($paths) <= 3 || $paths[2] !== 'ads') {
return;
}
// Enable the main event we are interested in
$this->enable([
'onAdminSave' => ['onAdminSave', 0]
]);
}
public function onAdminSave(Event $e)
{
$page = $page = $e['object'];
$header = $page->header();
$id = $this->myUniqueIdGenerator();
$header->routes['aliases'] = [
"/api/$id",
"/api/maison/$id",
];
}
Please consider the above code as a rough sketch. Adapt code for your specific needs.