Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

404 errors with Codeigniter on nginx when accessing controller

I'm using Codeigniter for my website, the root website works just fine which has a landing page, however I have a development section located /var/www/domain.com/www/dev/ which /var/www/domain.com/www/ is the root (landing page is stored there).

Now, when I go to domain.com/dev, my codeigniter website works fine, but when I load an controller, e.g. domain.com/index.php/search it gives me an 404 error.

In the error logs of domain.com it shows this:

2011/10/02 02:03:37 [error] 17042#0: *568 open() "/var/www/domain.com/www/dev/index.php/search" failed (20: Not a directory), client: xx.xx.xx.xx, server: domain.com, request: "GET /dev/$

Now I have no complete idea why it's doing this and how to resolve this issue. How can I stop this and also remove the "index.php" remove the URL because Codeigniter tutorials only contain apache's rewriterule which isn't valid on nginx.

like image 765
MacMac Avatar asked Apr 06 '26 02:04

MacMac


1 Answers

I believe that codeigniter uses the front-controller pattern, which will redirect all requests to index.php using a rewrite rule.

As the rewrite rules are for apache and not nginx, the server is actually looking for a directory called search which lives under another directory called index.php and so on.

I don't have much experience when it comes to nginx, but I believe this blog post can help you come up with rewrite rules on nginx.

like image 91
F21 Avatar answered Apr 08 '26 15:04

F21