Reputation: 370
I am new in cakephp trying to loading default controller as Pages
This is my route :
Router::redirect ('/', array('controller' => 'pages', 'action' => 'display'));
Router::connect('/pages/**', array('controller' => 'pages', 'action' => 'display'));
When I run "http://localhost/project/index.php" then its working fine but try with "http://localhost/project/" its not loading default controller (Pages)
Without htaccess & with htaccess its giving same issue.
This is error:
Controller class ProjectController could not be found.
Error:
The requested address '/project/index.php/project/' was not found on this server.
Upvotes: 2
Views: 574
Reputation: 370
Its resolved
Added baseUrl in app controller:
function beforeRender(){
$this->set('baseUrl', 'http://'.$_SERVER['SERVER_NAME'].Router::url('/'));
}
Removed App.baseUrl from Core.php :
Configure::write('App.baseUrl', env('SCRIPT_NAME'));
now its working fine on: http://localhost/app/
Upvotes: 0
Reputation: 85
As per cakephp manual :
http://book.cakephp.org/3.0/en/development/routing.html#redirect-routing
You should try
Router::scope('/', function ($routes) {
$routes->redirect(
'/home/*',
['controller' => 'Articles', 'action' => 'view'],
['persist' => true]
// Or ['persist'=>['id']] for default routing where the
// view action expects $id as an argument.
);
})
Instead of Router::redirect.You should try this method once, might issue got resolved.
Upvotes: 0
Reputation: 5577
You are running in subdirectory, so you should set RewriteBase:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /project/index.php?url=$1 [QSA,L]
</IfModule
Upvotes: 0