Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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 http://example.com/upload on http://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.



2.8k
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.