CodeIgniter returns 404 for all routes but works

别说谁变了你拦得住时间么 提交于 2020-01-05 10:10:04

问题


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.


回答1:


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




回答2:


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...



来源:https://stackoverflow.com/questions/17806531/codeigniter-returns-404-for-all-routes-but-works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!