Bug #84865
closedRedirect functionality from pageNotFoundAndExit cant set the header status code
0%
Description
Hello,
I have found the following bug in the currently LTS version 8.7.12. My my case i would like to send my user to a fallback page when going to a old page, or a page that not exists.
I have used the following Code
...
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = 'REDIRECT:/refererpage-example.html';
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling_statheader'] = 'HTTP/1.0 404 Not Found';
$GLOBALS['TSFE']->pageNotFoundAndExit();
...
i would like to send the header statuscode 404 (Page not found). But I only got the Header Code 303
after debugging i have found the following:
https://api.typo3.org/typo3cms/current/html/_typo_script_frontend_controller_8php_source.html#l01970
TypoScriptFrontendController->pageNotFoundAndExit();
> Line:1973 -> $this>pageNotFoundHandler();
-> Line:2076 -> [condition::TRUE] GeneralUtility::isFirstPartOfStr($code, 'REDIRECT:')
-> Line:2077 -> HttpUtility::redirect(substr($code, 9));
and this is the misstake.
In Line 2077 will used the HttpUtility redirect method and the status code is not given to the method (second argument)
this is needed to solve the bug
Line:2077 -> HttpUtility::redirect(substr($code, 9), $header);
Thx a lot
Updated by Benni Mack over 6 years ago
- Status changed from New to Needs Feedback
hey Tommy,
well, the main issue is that if you don't send a 30x header, then your client won't follow redirects (according to the standards). I consider REDIRECT (and 404 handling) one of the worst implementations we have in TYPO3 core.
For our customer projects I use:
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = '/refererpage-example.html';
which should solve your issue!
Updated by Tommy Bley over 6 years ago
Hello Benni,
i have test other ways in I have found the solution:)
When I make a redirect in PHP and will throw a 404 state, than i must write down the following:
header('Location: http://www.example.com/regererpage-example.html', true, 404);
The solution can be found in the official documentation from PHP. (http://php.net/manual/en/function.header.php)
The problem in Typo3 is that in the HttpUtility set the headerState in a extra header command e.g.
https://api.typo3.org/typo3cms/current/html/_http_utility_8php_source.html#l00091
header("HTTP/1.0 404 Not Found");
but for the case 40x you need to override the state in the location command as the third argument
Updated by Markus Klein over 6 years ago
- Target version deleted (
8.7.13) - Is Regression deleted (
Yes)
Updated by Markus Klein over 6 years ago
I cannot find the quoted solution in the official docs.
And I am not sure whether this makes sense at all. If the browser asks for URL /this/specific/page/ and it does not exist, you shall tell the browser with a 404 status that the document was "not found". (you may send some nice content along with the response)
I consider the answer "404, not found" but look "there" (location header) semantically wrong, because obviously you know that URL and that there is something to show instead, which can be found somewhere else. Hence the right answer must be "30x, ..found..".
Updated by Tommy Bley over 6 years ago
Thx Markus,
its my fault and its correct. After long searching in the web and a lot of reading. when i have a 404 Page I cant redirect to a other page. When Redirect to a other page, than i have allways a 30x response. Only when i stay on the same page, I can send a 404 header.
But thx for the response, the issue can be closed :)
Updated by Wouter Wolters over 6 years ago
- Status changed from Needs Feedback to Closed
Closed as requested.