Something Wrong with the URi and Routing....

apache 2 web root:

Alias /yzoix "/yzoix/public"
<Directory "/yzoix/public">
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>

web directory:

/yzoix
  -- app
  -- public
     -- index.php
     -- .htaccess

And in the file .htacess:

AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /yzoix/
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
    #RewriteRule .* index.php/$0 [PT]
</IfModule>

The Routing:

$router->add('/:controller/:action/:params', array(
    'namespace' => 'MY\Controllers',
    'controller' => 1,
    'action' => 2,
    'params' => 3,
));

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

$router->notFound(array(
    "controller" => "index",
    "action" => "e404"
));

Then , the URL http://.../yzoix/ got 404 ERROR

This is correct: http://.../yzoix/index!

How to enable this URL:http://.../yzoix/ , that's without 'index'

Note the trailing slash after yzoix/

You have to add route with trailing slash also or Ignore trailing slash in router:

$di->set('router', function() use ($config) {
    $router = new \Phalcon\Mvc\Router();

    // This is the important part
    $router->removeExtraSlashes(true);

    // Your routes here
    return $router;
});

Here is my universal route declaration for my "cms" area:

$router->add('/cms/:controller/:action/([0-9]+)/:params', ['module' => 'backend', 'controller' => 1, 'action' => 2, 'id' => 3, 'params' => 4]);
$router->add('/cms/:controller/:action', ['module' => 'backend', 'controller' => 1, 'action' => 2]);
$router->add('/cms/:controller', ['module' => 'backend', 'controller' => 1, 'action' => 'index']);


10.2k
edited Jun '16

Thanks Nikolay !

When I visit the URL http://.../yzoix , it will automaticly redirect to http://.../yzoix/ (a addtional trailing slash), even after I add:

$router->removeExtraSlashes(true);

@Xaero7 this is htaccess issue. Please take a look at INVO project here: https://github.com/phalcon/invo

Note: there are two htaccess files. One in root and one in public folder.



10.2k
edited Jun '16

yes, the htaccess files both in root and public are exactly the same to INVO project

@Xaero7 this is htaccess issue. Please take a look at INVO project here: https://github.com/phalcon/invo

Note: there are two htaccess files. One in root and one in public folder.