Bug #16988
closedpageNotFound doesn't perform a real 301-redirect
0%
Description
I configured the pageNotFound-handling, that in case of a 404-error , typo3 should send a "301 Moved Permanently" header an redirect to the root page.
$TYPO3_CONF_VARS['FE']['pageNotFound_handling'] = 'http://www.example.org';
$TYPO3_CONF_VARS['FE']['pageNotFound_handling_statheader'] = 'HTTP/1.x 301 Moved Permanently';
But it didn't works. The header is sent correctly but there's no real redirect to my root page. Only the content of the root-page is presented under the wrong url.
To make it work , i extended the pageNotFoundHandler in class.tslib_fe.php
Orig :
if (false === $content) {
// Last chance -- redirect
header('Location: '.t3lib_div::locationHeaderUrl($code));
} else {
Changed:
if ( (false === $content) || (strstr($header,'Moved Permanently')) ) {
// Last chance -- redirect
header('Location: '.t3lib_div::locationHeaderUrl($code));
} else {
now, the method checks if "Moved Permanently" is used in the pageNotFound_handling_statheader . If so, it will perform the real redirect.
(issue imported from #M4988)
Files
Updated by Helmut Hummel about 17 years ago
If you want to send a redirect, if a page is not found, aou can simply use
$TYPO3_CONF_VARS['FE']['pageNotFound_handling'] = 'REDIRECT:http://www.example.org'; (302 Header is sent)
Or you can use USER_FUNCTION:/file.php:class->function() in order to do what you want...
Updated by Dirk Diebel about 17 years ago
i think this is obsolete.
in version 4.1.2 i fixed , the problem this way:
$TYPO3_CONF_VARS['FE']['pageNotFound_handling'] = ' REDIRECT: http://www.example.org';
$TYPO3_CONF_VARS['FE']['pageNotFound_handling_statheader'] = 'HTTP/1.x 301 Moved Permanently';
Updated by Chris topher about 14 years ago
Resolved, fixed.
In current versions (I just tested this again with 4.5.0alpha3, but this also works with older versions) you can also get a 301 Redirect with these settings:
$TYPO3_CONF_VARS['FE']['pageNotFound_handling'] = '/404.html'; // A page inside TYPO3
$TYPO3_CONF_VARS['FE']['pageNotFound_handling_statheader'] = 'HTTP/1.1 404 Not Found';