Search code examples
typo3http-status-code-404typo3-8.xrealurl

TYPO3 how to render a Page on 404 with correct status code


we are using: TYPO3 8.7.27 RealUrl 2.5.0

following scenario - a user enters a link that does not exist within our site - so we expect the behaviour that a 404 page gets rendered - we managed to achive that but we do not have the correct status code because we used a simply redirect within the install tool:

[FE][pageNotFound_handling] = "REDIRECT:/404" 
[FE][pageNotFound_handling_statheader] = "HTTP/1.0 404 Not Found"

we also use our 404 page for cHash comparison errors but thats just a sidenote.

so what happens is the user requests the data from the wrong url, we send the correct 404 followed by a redirect to a certain page.

how can we directly render a page in the first place, the url should stay the same and we just render our whole TYPO3 page (no static file) with the 404 text-information.


Solution

  • You should use this instead:

    [FE][pageNotFound_handling] = "/404"
    

    This will instruct TYPO3 to download the page at the given "URL" and output its content together with the expected 404 status code. Notice that it might be necessary to use an absolute URL here.

    From the DefaultConfigurationDescription.php:

    pageNotFound_handling

    ... String: Static HTML file to show (reads content and outputs with correct headers), e.g. "notfound.html" or "http://www.example.org/errors/notfound.html"

    You can drop the pageNotFound_handling_statheader option since it defaults to 404.