From 094d6dfc3860b6322deed612829c57dde83581da Mon Sep 17 00:00:00 2001 From: Josh Vanderwillik Date: Tue, 11 Nov 2014 19:02:38 -0500 Subject: [PATCH] Make HTTPS compatible with a Ghost module closes #4434 - Change an incorrect redirect --- core/server/middleware/index.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/core/server/middleware/index.js b/core/server/middleware/index.js index 3cb1245364..601f7a0c4e 100644 --- a/core/server/middleware/index.js +++ b/core/server/middleware/index.js @@ -178,6 +178,7 @@ function checkSSL(req, res, next) { if (isSSLrequired(res.isAdmin)) { if (!req.secure) { var forceAdminSSL = config.forceAdminSSL, + configUrl, redirectUrl; // Check if forceAdminSSL: { redirect: false } is set, which means @@ -186,12 +187,20 @@ function checkSSL(req, res, next) { return res.sendStatus(403); } - redirectUrl = url.parse(config.urlSSL || config.url); + configUrl = url.parse(config.urlSSL || config.url); + + redirectUrl = configUrl.path; + if (req.url[0] === '/' && redirectUrl[redirectUrl.length - 1] === '/') { + redirectUrl += req.url.slice(1); + } else { + redirectUrl += req.url; + } + return res.redirect(301, url.format({ protocol: 'https:', - hostname: redirectUrl.hostname, - port: redirectUrl.port, - pathname: req.path, + hostname: configUrl.hostname, + port: configUrl.port, + pathname: redirectUrl, query: req.query })); }