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

Accept .php url end

Hello,

How can I accept address with .php end? I need that one only for one page.

I'd like to have the same action as on https://example.com/upload on https://example.com/upload.php

edited Sep '15

You could use an explicit route rule:

$router->add('/upload\.php', array(
    'controller' => 'upload',
    'action' => 'index',
));

Be aware that routes are handled with regex, so you'll need to escape the dot character!

What in case when I do not use $router?

But you do, it's a default service! :]

You could do this in your public/index.php:

$app = new Phalcon\Mvc\Application();
$app->router->add('/upload\.php', array(
    'controller' => 'upload',
    'action' => 'index',
));

I've tried this in services and index and don't work :( It redirect me to sign in page (I'm using dispatcher)

Why do you need it to end with .php? :-)

Because some old data are going thought upload.php and I can't change it.



6.5k
Accepted
answer

Issue fixed

It should be:

$router->add('/upload.php', array(
    'controller' => 'upload',
    'action' => 'index',
));

not:

$router->add('/upload\.php', array(
    'controller' => 'upload',
    'action' => 'index',
));
edited Apr '16

Yes, since Phalcon router service will read literaly URL request like that. You can put anything as route will match any pattern defined there. Try with '/default.aspx' :) The problem would be if you actually had upload.php script/file present physically on a filesystem. In case of nginx, who will first try to serve file on it's own prior to handling a route to index.php / Front Page Controller of PhalconPHP.