Typo3, RealURL and a real 404 error page


When you setup your Typo3 installation with realURL you may also want to add a more informative 404 error page. At a first look this doesn’t seems to be a problem. Just open your localconf.php and add these lines at the end of the file.

$TYPO3_CONF_VARS[“FE”][“pageNotFound_handling”] = ‘http://www.example.com/not-found-404.html’;
$TYPO3_CONF_VARS[“FE”][“pageNotFound_handling_statheader”] = ‘HTTP/1.1 404 Not Found’;

An other way is to use the Install Tool -> All Configuration and setting the fields.

Try typing a wrong URL and be happy to see your custom 404 error page.
But stop! There is a small problem. You are not able to see this problem now. But if you try to add a Google site verification you’ll have the problem. So why? This problem is, that Typo3 redirects to the error page. This means not a 404 error code but a 301 followed by 200 (you custom error page) is send. That’s bad!
OK! So we need another way to setup your custom 404 error page in Typo3. Luckily we can setup not only a custom page but also a custom script! That’s where we’ll start:

$TYPO3_CONF_VARS[“FE”][“pageNotFound_handling”] = ‘USER_FUNCTION:fileadmin/pageNotFoundHandling.php:user_pageNotFound->pageNotFound’;

This will execute the script fileadmin/pageNotFoundHandling.php which contains these:

<?php

class user_pageNotFound {
function pageNotFound($param,$ref) {
print "<html>\n<head>\n<title>404 Not found</title>\n";
print "<meta http-equiv="refresh" CONTENT="0;URL=/not-found.html">\n";
print "</head>\n<body>\n";
print "<!--
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
Just a placeholder to reach the limit of a custom 404 page\n
-->";
print "</body>\n</html>\n";
}
}

?>

It’s important not to use the Header( “Location: ..”); statement since this is exactly what Typo3 does per default. Only the refresh via the meta tag will work!
Don’t forget to change the path to your error page 🙂

If you have any query then feel free to contact me at Jainish Senjaliya

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s