3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\HTTPException;
24 use Friendica\BaseModule;
26 use Friendica\Network\HTTPException;
27 use Psr\Http\Message\ResponseInterface;
29 class PageNotFound extends BaseModule
31 protected function content(array $request = []): string
33 throw new HTTPException\NotFoundException(DI::l10n()->t('Page not found.'));
36 public function run(array $post = [], array $request = []): ResponseInterface
38 /* The URL provided does not resolve to a valid module.
40 * On Dreamhost sites, quite often things go wrong for no apparent reason and they send us to '/internal_error.html'.
41 * We don't like doing this, but as it occasionally accounts for 10-20% or more of all site traffic -
42 * we are going to trap this and redirect back to the requested page. As long as you don't have a critical error on your page
43 * this will often succeed and eventually do the right thing.
45 * Otherwise we are going to emit a 404 not found.
47 $queryString = $this->server['QUERY_STRING'];
48 // Stupid browser tried to pre-fetch our Javascript img template. Don't log the event or return anything - just quietly exit.
49 if (!empty($queryString) && preg_match('/{[0-9]}/', $queryString) !== 0) {
53 if (!empty($queryString) && ($queryString === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
54 $this->logger->info('index.php: dreamhost_error_hack invoked.', ['Original URI' => $this->server['REQUEST_URI']]);
55 $this->baseUrl->redirect($this->server['REQUEST_URI']);
58 $this->logger->debug('index.php: page not found.', [
59 'request_uri' => $this->server['REQUEST_URI'],
60 'address' => $this->server['REMOTE_ADDR'],
61 'query' => $this->server['QUERY_STRING']
64 return parent::run($post, $request); // TODO: Change the autogenerated stub