From f2e60806dac198228d7294bb5a8be4aaf504110a Mon Sep 17 00:00:00 2001 From: Timothy Stapleton Date: Sun, 9 Jun 2019 22:48:37 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20redirects=20to=20absolut?= =?UTF-8?q?e=20URLs=20(#10777)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #10776 When the "to" property of the redirect includes a host (implying an external or fully qualified url) we skip replacing any paths and redirect straight to it, rather than modifying the URL with the sites sub-directory. --- core/server/web/shared/middlewares/custom-redirects.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/server/web/shared/middlewares/custom-redirects.js b/core/server/web/shared/middlewares/custom-redirects.js index 02966000be..5fa3088fd8 100644 --- a/core/server/web/shared/middlewares/custom-redirects.js +++ b/core/server/web/shared/middlewares/custom-redirects.js @@ -53,7 +53,9 @@ _private.registerRoutes = () => { const fromURL = url.parse(req.originalUrl); const toURL = url.parse(redirect.to); - toURL.pathname = fromURL.pathname.replace(new RegExp(redirect.from, options), toURL.pathname), + toURL.pathname = (toURL.hostname) + ? toURL.pathname + : fromURL.pathname.replace(new RegExp(redirect.from, options), toURL.pathname); toURL.search = fromURL.search; res.set({