开发者

CakePHP 404 on existing controller

开发者 https://www.devze.com 2023-01-13 15:25 出处:网络
(I\'m really hoping I put in enough due dilligence on google and the search bar before posting this) I\'m getting started with CakePHP and just created my first model, controller, and view.

(I'm really hoping I put in enough due dilligence on google and the search bar before posting this)

I'm getting started with CakePHP and just created my first model, controller, and view.

When I browse to http://localhost/~me/MyApp/Lists I get a 404 and I'm not sure why

Here's my controller

<?php
    class ListsController extends AppController 
    {    
        var $name = 'Lists';

        function index()
        {
            $this->set('lists', $this->List->find('all'));
        }
    }
?>

I would think it's a .htaccess issue but when I browse to http://localhost/~me/MyApp/app or http://localhost/~me/MyApp/index I get a "Missing Controller" error page. Granted both of these URLs would otherwise point at an actual file or directory.

Can anyone tell me why I would be getting this 404 on my controllers?

Update for a couple comments left below (see the answer by Leo)

My .htacces for the application root开发者_运维问答

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

My .htaccess for the CakePHP webroot

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>


I think the problem is in the /~me/. Try to move your project at least on: http://localhost/MyApp

I remember that we had such problem long time ago. It's possible to fix it, but for sure you wont leave the site with such url in the production server, so just change the url :)


Look at app/webroot/index.php and make sure the root, app, and core paths are defined correctly.

Another thing to try (although I doubt this is your problem) is to add RewriteBase /~me to all your htaccess files (there is one in the root directory of your site, one in the app directory, and one in the webroot directory).


Your url should be http://localhost/~me/MyApp/lists with 'lists' lowercased. And url http://localhost/~me/MyApp/app and http://localhost/~me/MyApp/index would get you missing controller page because if you use .htaccess, all request will be handled by app/webroot/index.php.


Looks to me like you don't have mod_rewrite working properly. Create a phpinfo.php file containing only the following:

<?php echo phpinfo() ?>

Put it in webroot then access it as http://localhost/~me/MyApp/phpinfo.php

In the browser do ctrl-f and search for 'rewrite'. If it's not there, it's not set up.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号