1. Go to this page and download the library: Download httpsoft/http-router library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// Only for example.com
$router->get('page', '/page', $handler)
->host('example.com')
;
// Only for subdomain.example.com
$router->get('page', '/page', $handler)
->host('subdomain.example.com')
;
// Only for shop.example.com or blog.example.com
$router->get('page', '/page', $handler)
->host('(shop|blog).example.com')
;
$router->group('/post', static function (RouteCollector $router): void {
// '/post/post-slug'
$router->get('post.view', '/{slug}', ViewHandler::class)->tokens(['slug' => '[\w-]+']);
// '/post' or '/post/2'
$router->get('post.list', '/list{[page]}', ListHandler::class)->tokens(['page' => '\d+']);
});
// The result will be equivalent to:
$router->get('post.view', '/post/{slug}', ViewHandler::class)->tokens(['slug' => '[\w-]+']);
$router->get('post.list', '/post/list{[page]}', ListHandler::class)->tokens(['page' => '\d+']);