Send proper HTTP code for 404 pages

367
Enhancement
Erwin
Jack
3.2.2
3.2.1
Core
Completed
Normal
Normal
4 years ago
3 years ago
0

Description

Hello,

I have noticed that, if I get a "not found page" (the "He's dead, Jim!" one), Traq doesn't change the HTTP code and so returns a 200 OK. That's not a really important thing, but I think it would be cleaner if Traq could send the proper HTTP status code in such a case.

As far as I understand, I think it could be done in vendor/avalon/core/controller.php, by adding a new key to the $_render array (let's say "http_status" for example) defaulted to null, then adding this line in the show_404 method:

$this->_render['http_status'] = '404';

And in the __shutdown method:

    // Check if we have to send a specific HTTP code
if (!is_null($this->_render['http_status'])) {
        if ($this->_render['http_status'] === '404') {
            header("HTTP/1.0 404 Not Found");
    }
    }    

The same could be done for the no_permission page as well with a 403 Forbidden code.

Ticket History

4 years and 4 months ago by Jack

  • Set Component to Core
  • Closed ticket as Completed
  • Assigned ticket to Jack

Could also just call the header function in the action_404 and show_no_permission methods instead of having a bunch of lines of extra code in the __shutdown method.

4 years and 4 months ago by Erwin

Ok, thank you :) And sorry for the text formatting, it broke for some reason. I suspect a Firefox extension to break editors since I had some issues elsewhere as well, I have yet to find the guilty...