$route['404_override'] not sending 301 status code with redirection to custom error page |
[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
[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 :-) |
Welcome Guest, Not a member yet? Register Sign In |