From 6ff3389f6ef9fc008a6ce98efcd759eda440fa39 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 4 May 2019 09:16:37 +0200 Subject: [PATCH] add status code to System::externalRedirect --- src/Core/System.php | 16 ++++++++++++++-- src/Module/Diaspora/Fetch.php | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Core/System.php b/src/Core/System.php index e2966a9b0e..31934af5a7 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -223,15 +223,27 @@ class System extends BaseObject * Redirects to an external URL (fully qualified URL) * If you want to route relative to the current Friendica base, use App->internalRedirect() * - * @param string $url The new Location to redirect + * @param string $url The new Location to redirect + * @param int $code The redirection code, which is used (Default is 302) + * * @throws InternalServerErrorException If the URL is not fully qualified */ - public static function externalRedirect($url) + public static function externalRedirect($url, $code = 302) { if (empty(parse_url($url, PHP_URL_SCHEME))) { throw new InternalServerErrorException("'$url' is not a fully qualified URL, please use App->internalRedirect() instead"); } + switch ($code) { + case 302: + // this is the default code for a REDIRECT + // We don't need a extra header here + break; + case 301: + header('HTTP/1.1 301 Moved Permanently'); + break; + } + header("Location: $url"); exit(); } diff --git a/src/Module/Diaspora/Fetch.php b/src/Module/Diaspora/Fetch.php index 46d9388062..bcb33e3359 100644 --- a/src/Module/Diaspora/Fetch.php +++ b/src/Module/Diaspora/Fetch.php @@ -4,6 +4,7 @@ namespace Friendica\Module\Diaspora; use Friendica\BaseModule; use Friendica\Core\Protocol; +use Friendica\Core\System; use Friendica\Model\Item; use Friendica\Model\User; use Friendica\Network\HTTPException; @@ -44,7 +45,7 @@ class Fetch extends BaseModule if (Strings::normaliseLink($host) != Strings::normaliseLink($app->getBaseURL())) { $location = $host . "/fetch/" . $app->argv[1] . "/" . urlencode($guid); - $app->redirect($location); + System::externalRedirect($location, 301); } } -- 2.39.5