0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

🐛Fixed custom redirects to forward hashes correctly (#10319)

closes #10290
This commit is contained in:
Greg Hart 2019-01-15 14:26:18 -08:00 committed by Katharina Irrgang
parent a1f0169edf
commit 418e958c69

View file

@ -22,6 +22,13 @@ _private.registerRoutes = () => {
validation.validateRedirects(redirects);
redirects.forEach((redirect) => {
/**
* Extract target info, such as hash.
*
* Required to re-formulate the correct endpoint.
*/
const parsedTo = url.parse(redirect.to);
/**
* Detect case insensitive modifier when regex is enclosed by
* / ... /i
@ -55,10 +62,10 @@ _private.registerRoutes = () => {
res.set({
'Cache-Control': `public, max-age=${maxAge}`
});
res.redirect(redirect.permanent ? 301 : 302, url.format({
pathname: parsedUrl.pathname.replace(new RegExp(redirect.from, options), redirect.to),
search: parsedUrl.search
pathname: parsedUrl.pathname.replace(new RegExp(redirect.from, options), parsedTo.pathname),
search: parsedUrl.search,
hash: parsedTo.hash
}));
});
});