We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Router problem with .html

I've a problem with the "Router" component.

Router config:

$router->add('/([a-z0-9-]+)/([a-z0-9-]+).html', array( 'module' => 'frontend', 'controller' => 'content', 'action' => 'show', 'category' => 1, 'slug' => 2 ))->setName('showPage');

URL: https://localhost/test/request-gca.html

When I remove the ".html" in my router and remove the ".html" from my url, I can access the page. Otherwise I'll get a 404.

Routes like

$router->add('/metartaf_{icao}.html', array( 'module' => 'frontend', 'controller' => 'airports', 'action' => 'metartaf' ))->setName('airportMetarTafDetail');

are no problem. I can still access them but with a leading "/" in front of my regex-group ".html" seems to cause problems.

Is that a bug or am I doing it wrong?

edited Jun '16

Does your web server interfere with .html extension? Usually it will try to handle it first as a static file.

In case of nginx:

    index index.html index.htm index.php;

BUT, even with that, if you don't have such file on a file-system it should fall back to the Front Page controller (index.php) which will trigger your Router component.

Have you tried with this example:

// Matches "/manual/en/translate.adapter.html"
$router->add(
    "/manual/([a-z]{2})/([a-z\.]+)\.html",
    array(
        "controller" => "manual",
        "action"     => "show",
        "language"   => 1,
        "file"       => 2
    )
);

I'm still in the php scope. I'm receiving the 404 in the phalcon dispatcher.

I added your snippet and copied the URL. Still doesn't work. I'm using phalcon 2.0.13

Whoops. I should have created the controller and action, too. Your snippet works. I'll try how I get it along with my case. Thank you.

edited Jun '16

When I add a non-regex string to the URL it works.

route: "/p/([a-z0-9-]+)/([a-z0-9-]+).html"

url: /p/test/request-gca.html