From 255191d9c7c954698ab7b9c089c0bf93690ee46e Mon Sep 17 00:00:00 2001
From: Steffen Gebert <steffen.gebert@typo3.org>
Date: Wed, 23 Mar 2011 23:03:21 +0100
Subject: [PATCH] [BUGFIX] Send header Error 404 in case of page not found
 errors

If a page is not found, status 404 has to be sent.

Due to a recent change, an Exception is thrown instead of exiting.
As the Exception Handler overwrites the status 404 with a 503, this
code was sent to the client.

Change-Id: Ia6c7686c720863aa80e390c452527cabb338bde3
Resolves: #24945
Reviewed-on: http://review.typo3.org/1245
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
---
 typo3/sysext/cms/tslib/class.tslib_fe.php | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/typo3/sysext/cms/tslib/class.tslib_fe.php b/typo3/sysext/cms/tslib/class.tslib_fe.php
index 9fccf9e83dbf..16204574bd0f 100644
--- a/typo3/sysext/cms/tslib/class.tslib_fe.php
+++ b/typo3/sysext/cms/tslib/class.tslib_fe.php
@@ -1011,9 +1011,11 @@
 					$this->pageNotFoundAndExit('The requested page does not exist!');
 				} else {
 					$message = 'The requested page does not exist!';
-					header('HTTP/1.0 404 Page Not Found');
+					header(t3lib_utility_Http::HTTP_STATUS_404);
 					t3lib_div::sysLog($message, 'cms', t3lib_div::SYSLOG_SEVERITY_ERROR);
-					throw new RuntimeException($message, 1294587208);
+					$messagePage = t3lib_div::makeInstance('t3lib_message_ErrorpageMessage', $message);
+					$messagePage->output();
+					exit;
 				}
 			}
 		}
@@ -1024,9 +1026,11 @@
 				$this->pageNotFoundAndExit('The requested page does not exist!');
 			} else {
 				$message = 'The requested page does not exist!';
-				header('HTTP/1.0 404 Page Not Found');
+				header(t3lib_utility_Http::HTTP_STATUS_404);
 				t3lib_div::sysLog($message, 'cms', t3lib_div::SYSLOG_SEVERITY_ERROR);
-				throw new RuntimeException($message, 1294587209);
+				$messagePage = t3lib_div::makeInstance('t3lib_message_ErrorpageMessage', $message);
+				$messagePage->output();
+				exit;
 			}
 		}
 
@@ -1455,7 +1459,10 @@
 
 			// Create response:
 		if (gettype($code)=='boolean' || !strcmp($code,1))	{	// Simply boolean; Just shows TYPO3 error page with reason:
-			throw new RuntimeException('The page did not exist or was inaccessible.' . ($reason ? ' Reason: ' . htmlspecialchars($reason) : ''), 1294587213);
+			$message = 'The page did not exist or was inaccessible.' . ($reason ? ' Reason: ' . htmlspecialchars($reason) : '');
+			$messagePage = t3lib_div::makeInstance('t3lib_message_ErrorpageMessage', $message);
+			$messagePage->output();
+			exit;
 		} elseif (t3lib_div::isFirstPartOfStr($code,'USER_FUNCTION:')) {
 			$funcRef = trim(substr($code,14));
 			$params = array(
@@ -1555,7 +1562,9 @@
 				echo $content;	// Output the content
 			}
 		} else {
-			throw new RuntimeException($reason ? htmlspecialchars($reason) : 'Page cannot be found.', 1294587216);
+			$message = ($reason ? 'Reason: ' . htmlspecialchars($reason) : 'Page cannot be found.');
+			$messagePage = t3lib_div::makeInstance('t3lib_message_ErrorpageMessage', $message);
+			$messagePage->output();
 		}
 		exit();
 	}
-- 
GitLab