CodeIgniter returns 404 for all routes but works

2019-07-23 06:10发布

I have strange problem with CodeIgniter and routing system and can't find solution for it, so: I have several routes such as

'forum/(:num)'
    => 'forum/category/$1',
'forum/(:num)/(page:any)'
    => 'forum/category/$1/$2',

and them works, but return 404 code in header.

I mean I don't get 404 page, correct HTML returns and page's content displays correctly for my forum's categories. But I'm getting 404 in header (Network tab in Firebug), so I can't work with POST data correctly.

If I request /forum/ - 200 Ok returns, but when I trying to get routed page, I get right page, but with 404 Not Found.

I'm using PHP5.4+Apache2 on Linux host, if it will help You to give me solution.

2条回答
Luminary・发光体
2楼-- · 2019-07-23 06:22

None of these worked, but I did this instead:

At the end of my controller I put this:

$this->output->set_status_header('200');

and actually though that worked, the problem turned out to be a controller name that conflicted with a real directory name...

查看更多
时光不老,我们不散
3楼-- · 2019-07-23 06:29

I've found solution! Maybe it will save someone's time.

Problem wasn't in CodeIgniter, I've found solution in activation mod_rewrite. Yes, that worked, but wan't activated in Apache.

Just try to do

sudo a2enmod rewrite

and restart apache service after

sudo service apache restart

And all routed pages will return 200 Ok

查看更多
登录 后发表回答