• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
$route['404_override'] not sending 301 status code with redirection to custom error page

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

redirect($route['404_override'], 'location', 301); // as per the codeigniter docs

So I changed it to this:

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
$route['404_override'] = 'e/not_found';
- is there any way to make this actually send out the 301 status code? I guess I'd need to hack at the core? This would be the ideal handling for SEO reasons, correct?

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

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:
before you load the views.

Worked for me, hopefully it will help others :-)

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.