Php – header(“location”) causes [500] internal server error

apachephpredirect

I cannot figure out what could be causing this error. My Apache log is not recording any errors in the access log or error log regarding the page, yet somehow whenever I uncomment the header() line I get a 500 Internal Server Error. It can't be coming from PHP's fatal error when content is outputted before header() is called, that wouldn't cause a 500 would it?

header("Location: /offices/page-".ceil($cache->size() / 15));

I tested $cache->size() and it's returning 22, so it should append a 2 to the end of the string and redirect. I did have ob_start() called before the header() but I tried calling ob_end_clean() right before it and it still did nothing…

I even tried putting header("Location: /offices"); at the very beginning of the file and it still gives me a 500.

Best Solution

Another reason might be - you need to remove space after location :

header("location :
header("location:

If that's not your problem, then try to check the php & apache error logs.

Related Question