$route['404_override'] not sending 301 status code with redirection to custom error page - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: $route['404_override'] not sending 301 status code with redirection to custom error page (/showthread.php?tid=41095) |
$route['404_override'] not sending 301 status code with redirection to custom error page - El Forum - 04-27-2011 [eluser]taber[/eluser] Hey just noticed using CI 2.0.2, redirect() requires the 3rd parameter to be a string, I think. I was trying it out earlier, and this was showing a 200 OK in Chrome on Mac... Code: redirect($route['404_override'], 'location', 301); // as per the codeigniter docs So I changed it to this: Code: redirect($route['404_override'], 'location', '301'); // '301' in single quotes And it worked fine, showing the "301 Permanently moved" status code in Chrome. Just thought this may be a bug! Edit: Something else must have been at play, looks like it's working without the quotes now. Sorry about that! Edit #2!! Ah-ha! So, I'm using my custom error redirection function (thanks to this post: /forums/viewthread/184877/) for when a method in my class fails... which is working using the method above... But I noticed that if I try hitting a method that doesn't exist (eg: http://mysite.com/home/fewijfiowewioif) it will throw the 200 OK and no 301. I'm using Code: $route['404_override'] = 'e/not_found'; 1) User tries accessing /home/keopfkwefow 2) CI sends a 301, redirects using Location to /e/not_found 3) Custom error page is displayed Thanks, <3 CI -Taber $route['404_override'] not sending 301 status code with redirection to custom error page - El Forum - 06-10-2013 [eluser]Flemming[/eluser] I realise this is an old thread but thought I would post my answer in case anyone else is still having this problem (with the 404 override sending a 200 OK status) In your custom error controller add: Code: $this->output->set_status_header('404'); Worked for me, hopefully it will help others :-) |