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

phalcon base uri

Hi, I have a problem with the base uri of my phalcon app.

my domain structure looks like: 'https://www.example.com/some_directory/my_project/'

I'm having truble configuring phalcon, when i enter this address www.example.com/some_directory/my_project/ phalcon thinks that "some_directory" is a controller and throws me out a 404. instead it should go to default controller and default action (that i configured in the router) when I enter the site. also any href on the site i build like '<a href="/relative_path"></a>' and when I click on that link it sends me to root instead of the base-uri .

my app structure is regular MVC app, like:

myproject/ app/ config/ controllers/ library/ forms/ models/ plugins/ views/ public/ bootstrap/ css/ js/

I tried manipulating .htaccess , adding RewriteBase and changing the base uri on config file . nothing helped.

any help will be appreciated. Thanks a lot, Alex.

Sounds like you need to update your /config/config.php.

Did you set the 'baseUri' under application? Path should be '/somedirectory/myproject/'

i tried that already too, it didn't work also. the app acts like it is in the root dir of the domain instead of in the directory and everything i tried faild so far. it keep mixing up the directory in the root for a controller. any other sugestions please??

Can you paste your router config that you set up?

Also I'd suggest using $this->tag->linkTo(array('relativePath', 'display')); instead of anchor tags. If you put a forward slash in front of the relative path it will use the webroot instead of project root.

edited Aug '15

this is my router.php:

<?php

$router = new \Phalcon\Mvc\Router(false); $router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);

$router->setDefaultController('login'); $router->setDefaultAction('index');

/**

  • Standard MVC routes */ $router->add('/', []);

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

$router->add( '/:controller/:action', [ 'controller' => 1, 'action' => 2 ] );

$router->add( '/:controller/:action/:params', [ 'controller' => 1, 'action' => 2, 'params' => 3 ] );

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

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

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

$router->add('/games', array( 'controller' => 'soldigames', 'action' => 'index' ) );

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

$router->add('/view-images', array( 'controller' => 'images', 'action' => 'index' ) );

$router->add('/users/show', array( 'controller' => 'users', 'action' => 'regular' ) );

$router->add('/queue/show', array( 'controller' => 'users', 'action' => 'queue' ) );

$router->add('/winners', array( 'controller' => 'userswinners', 'action' => 'index' ) );

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

$router->add('/myZone', array( 'controller' => 'admins', 'action' => 'index' ) );

$router->add('/viewAllAdmins', array( 'controller' => 'admins', 'action' => 'viewAll' ) );

$router->add('/login', array( 'controller' => 'login', 'action' => 'logout' ) );

$router->add('/login/forgotPass', array( 'controller' => 'login', 'action' => 'forgotPass' ) );

$router->add('/lock', array( 'controller' => 'lock', 'action' => 'locked' ) );

$router->add('/logout', array( 'controller' => 'login', 'action' => 'logout' ) );

$router->addGet("/keepalive", "Lock::keepalive"); // Keep Alive the session

$router->addGet("/soldigames/getData", "Soldigames::show"); //manage game times

$router->addGet("/sponsorships/getData", "Sponsorships::show"); //manage sponsorships

$router->addGet("/view-images/getData", "Images::show"); // View all images $router->addGet("/view-images/del/{id}", "Images::del"); // Delete image

$router->addGet("/reports/getData", "Reports::show"); // View all reported images

$router->addGet("/users/regular/getData", "Users::showRegular"); // View all regular users $router->addGet("/users/regular/edit/{id}", "Users::r_edit"); // Manage regular users -> GET $router->addPost("/regular/edit/{id}", "Users::r_edit"); // Manage regular users -> POST $router->addGet("/users/regular/del/{id}", "Users::r_del"); // Delete regular users

$router->addGet("/users/queue/getData", "Users::showQueue"); // View all queue users $router->addGet("/users/queue/edit/{id}", "Users::q_edit"); // Manage queue users -> GET $router->addPost("/queue/edit/{id}", "Users::q_edit"); // Manage queue users -> POST $router->addGet("/users/queue/del/{id}", "Users::q_del"); // Delete queue users

$router->addGet("/winners/getData", "Userswinners::show"); // View all winners

$router->addGet("/admins/getData", "Admins::show"); // View all administrators

/**

  • END */

return $router;

?>