Custom Route And Make Friendly URL

I have 2 Module ! . Frontend vs Backend . Default is Frontend . My Route .

Important is I want hiding controller and action on url .

$di->set('router', function () {

    $router = new Router();
    $router->setDefaultModule("frontend");

    $router->add('/:module[/]?:controller[/]?:action[/]?:params', array(
        'module'     => 1,
        'controller' => 2,
        'action'     => 3,
        'params'     => 4
    ));

    $router->add('/backend[:/]', array(
        'module'     => 'backend',
        'controller' => 'index',
        'action'     => 'index',
    ));

    return $router;
});

I want generate url like this .

http://localhost/backend <--- work

http://localhost/backend/ <--- not work

http://localhost/frontend/ <--- not work

Paginator url like this

http://localhost/page/1

Category url and pagination like this

http://localhost/category-name-is-here/

ex :

http://localhost/sports/ <---- category sports

http://localhost/sports/page/1 <---- category sports with paginattion

And URL friendly like this

http://localhost/i-want-to-make-url-friendly-like-this-p1.html <---- frontend-index-post

Someone help me

    $router->removeExtraSlashes(true);
    ...
    $router->add("/myFriendlyURL/myFriendlyFuncName", array(
        'controller' => 'frontend',
        'action' => 'index',
    ));

about pagination, page numbers are passed as GET param, it's more difficult..not sure if that's could work:

    $router->add(
        "/([a-zA-Z0-9_-]+)/page/([0-9]+)",
        array(
            "controller" => "frontend",
            "action"     => "search",
            "category" => 1,
            "page" => 2,
         ));

you should be abble to grab the category and page in your search func using "$this->dispatcher->getParam("category" [or page]);"

then try to create your next/previous page link this :

    <?php echo $this->tag->linkTo("yourCategoryName/page/" . $page->next, "-next") ?>


3.7k
  $router->removeExtraSlashes(true);
  ...
  $router->add("/myFriendlyURL/myFriendlyFuncName", array(
      'controller' => 'frontend',
      'action' => 'index',
  ));

about pagination, page numbers are passed as GET param, it's more difficult..not sure if that's could work:

  $router->add(
      "/([a-zA-Z0-9_-]+)/page/([0-9]+)",
      array(
          "controller" => "frontend",
          "action"     => "search",
          "category" => 1,
          "page" => 2,
        ));

you should be abble to grab the category and page in your search func using "$this->dispatcher->getParam("category" [or page]);"

then try to create your next/previous page link this :

  <?php echo $this->tag->linkTo("yourCategoryName/page/" . $page->next, "-next") ?>

I was solved my problem ! Tks For Help !