开发者

In Codeigniter some URIs pass through index.php, some don't

开发者 https://www.devze.com 2023-03-03 12:49 出处:网络
Basically one controller (controller/topics.php, http://192.168.1.50/topics) gets passed through CI\'s index.php like its suppose to, yet another (controller/user.php, http://192.168.1.50/user) for so

Basically one controller (controller/topics.php, http://192.168.1.50/topics) gets passed through CI's index.php like its suppose to, yet another (controller/user.php, http://192.168.1.50/user) for some odd reason simply doesn't pass (I get an 404 error in browser). CodeIgniter and/or Apache2 are doing something funky and I can't figure it out: '.../user' gives me Apache's 404 page, yet '.../User' gives me CI's 404 page which means CI grabs URIs with uppercase controlle开发者_JAVA技巧r names and ignores some URIs with lowercase controller names (and then Apache tries to handle the URI).

Any ideas why and how to resolve?

P.S. - Yes, I did post my issue in CI's forum but I'm not having luck with their help. I'm running CodeIgniter 2.0.2 on a Linux distro (Ubuntu 10.10 with LAMP).


The problem was that the rewrite condition syntax is saying don’t route folders that BEGIN with i, c, j or u instead of folders whose name IS i, c, j or u. Coincidently my controller names which weren’t loading started with i (idea) and u (user).

I could just rename my static folders to their full names (“uploads” instead of “u”) and update the rewrite condition and resolve this issue, but I’d like to keep the names the same. Anyone happen to know the correct syntax for the rewrite condition to match exact names (instead of like or begins with)?


Check your controller name, the most common thing people (I find) do is copy their 'main' controller (say topics.php) and rename the file name to whatever.php

They start developing and the controller name stays 'Topics'. 404 is thrown due to the controller not being found (not the actual file)

ex: class Blog extends CI_Controller {...

if the above code is in a file called stuff.php. You will get a 404 if you are calling /stuff


I ran into a similar problem yesterday. The default controller can have an uppercase file name but any other controller would produce a 404 when uppercase. This was on a MAMP setup.

Make sure your controller reflects the file name as well.

class User extends CI_Controller {


in your htaccess... instead of

RewriteRule ^(.*)$ /index.php/$1 [L]

try

RewriteRule ^(.*)$ index.php/$1 [L]

and in your CI config set base_url as instructed (include trailing /!)

$config['base_url'] = 'http://www.site.com/';

That should do it.

0

精彩评论

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