summaryrefslogtreecommitdiff
path: root/app/Http/RequestHandlers/RedirectNotePhp.php
diff options
context:
space:
mode:
authorGreg Roach <greg@subaqua.co.uk>2023-11-02 12:53:06 +0000
committerGreg Roach <greg@subaqua.co.uk>2023-11-02 13:00:04 +0000
commit15c4f62c40de0c794536302daf7d5ec0548a1973 (patch)
treefe261c57c676123340bc8763d7b05c7c666bdd4f /app/Http/RequestHandlers/RedirectNotePhp.php
parent87123f232eeb719135b26fa902d2b3495ff0a0b3 (diff)
downloadwebtrees-15c4f62c40de0c794536302daf7d5ec0548a1973.tar.gz
webtrees-15c4f62c40de0c794536302daf7d5ec0548a1973.tar.bz2
webtrees-15c4f62c40de0c794536302daf7d5ec0548a1973.zip
Fix: #4873 - Add Link/rel=canonical to genealogy pages and redirects
Diffstat (limited to 'app/Http/RequestHandlers/RedirectNotePhp.php')
-rw-r--r--app/Http/RequestHandlers/RedirectNotePhp.php30
1 files changed, 10 insertions, 20 deletions
diff --git a/app/Http/RequestHandlers/RedirectNotePhp.php b/app/Http/RequestHandlers/RedirectNotePhp.php
index 255e017c5e..701fb871f5 100644
--- a/app/Http/RequestHandlers/RedirectNotePhp.php
+++ b/app/Http/RequestHandlers/RedirectNotePhp.php
@@ -20,8 +20,7 @@ declare(strict_types=1);
namespace Fisharebest\Webtrees\Http\RequestHandlers;
use Fig\Http\Message\StatusCodeInterface;
-use Fisharebest\Webtrees\Http\Exceptions\HttpNotFoundException;
-use Fisharebest\Webtrees\I18N;
+use Fisharebest\Webtrees\Http\Exceptions\HttpGoneException;
use Fisharebest\Webtrees\Note;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Services\TreeService;
@@ -37,22 +36,11 @@ use Psr\Http\Server\RequestHandlerInterface;
*/
class RedirectNotePhp implements RequestHandlerInterface
{
- private TreeService $tree_service;
-
- /**
- * @param TreeService $tree_service
- */
- public function __construct(TreeService $tree_service)
- {
- $this->tree_service = $tree_service;
+ public function __construct(
+ private readonly TreeService $tree_service,
+ ) {
}
- /**
- * @param ServerRequestInterface $request
- *
- * @return ResponseInterface
- * @throws HttpNotFoundException
- */
public function handle(ServerRequestInterface $request): ResponseInterface
{
$ged = Validator::queryParams($request)->string('ged', Site::getPreference('DEFAULT_GEDCOM'));
@@ -63,12 +51,14 @@ class RedirectNotePhp implements RequestHandlerInterface
$note = Registry::noteFactory()->make($nid, $tree);
if ($note instanceof Note) {
- return Registry::responseFactory()->redirectUrl($note->url(), StatusCodeInterface::STATUS_MOVED_PERMANENTLY);
+ $url = $note->url();
+
+ return Registry::responseFactory()
+ ->redirectUrl($url, StatusCodeInterface::STATUS_MOVED_PERMANENTLY)
+ ->withHeader('Link', '<' . $url . '>; rel="canonical"');
}
}
- $message = I18N::translate('This note does not exist or you do not have permission to view it.');
-
- throw new HttpNotFoundException($message);
+ throw new HttpGoneException();
}
}