cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Not fund .js, .png, .css and so on handled as index

Open johnnyajax opened this issue 13 years ago • 4 comments

There is bug in dispatcher. Have both event types attached to dispatch event:

if ($event->getType() == 'beforeNotFoundAction') and if ($event->getType() == 'beforeException')

url.com/js/main - is forwarded to IndexController->notFoundAction url.com/js/main.js - handled as IndexController->indexAction

basically any url with an .ext if not found on server is handled as index/index

for example: http://www.phalconphp.com/img/lalala.png

johnnyajax avatar Dec 18 '12 01:12 johnnyajax

Hi JohnnyAjax, this is not a bug, you need to change the default routes to allow the dot character on them:


$route = new Phalcon\Mvc\Router(false);

$router->add('/:controller', array(
     'controller' => 1
));

$router->add('/:controller/([a-zA-Z0-9\_\.]+)(/.*)*', array(
    'controller' => 1,
    'action' => 2,
    'params' => 3
));

However, using the dot in the controller/namespace or action is not recommended since those parameters are passed to an autoloader it would lead to open the possibility to read unauthorized files in your application.

ghost avatar Dec 18 '12 02:12 ghost

I would like it to be forwarded as 404 - as any not found controller/action

johnnyajax avatar Dec 20 '12 11:12 johnnyajax

I think http://www.phalconphp.com/lalala/lalla.jpg should be handled as http://www.phalconphp.com/lalala/lalla and not index page.

johnnyajax avatar Dec 20 '12 11:12 johnnyajax

I added a safe fix in 0.8.0 to handle the routes as you need

ghost avatar Dec 21 '12 19:12 ghost