PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 5, 2022

[FIXED] Why are my MVC controllers showing 404?

 March 05, 2022     codeigniter, mamp, php     No comments   

Issue

I've got an MVC project I'm trying to set up on a new computer. I'm using MAMP and codeigniter. For some reason I get a 404 error when I try to go to any controller.

But the weird thing is that the default controller, defined in the routes file seems to work ok.

Here's an example controller:

class Test_controller extends CI_Controller {
    public function index(){
       echo 'hello';
    }
}

When I go to localhost:8888/test_controller I get 404.

However, adding the following line to my routes.php...

$route['default_controller']="test_controller";

...and then navigating to localhost:8888 seems to load the controller ok.


Solution

You are missing the .htaccess, by default CI will need /index.php/controller to work, to remove the index.php you can use the HTaccess provided by Codeigniter or this one:

Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^ index.php [L] 

Place this outside the application folder with the name ".htaccess"



Answered By - killstreet
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing