0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Blog and Admin redirects with trailing slash (#8955)

no issue

- reduce the number of redirects
- before: you are redirected from example.com/ghost to admin.example.com/ghost and Ghost would detect a missing slash and redirect you to /ghost/
- now: you are redirected from example.com/ghost to admin.example.com/ghost/
This commit is contained in:
Katharina Irrgang 2017-08-30 18:42:00 +02:00 committed by Kevin Ansfield
parent 6a10c99088
commit 7dec743bba
2 changed files with 11 additions and 5 deletions

View file

@ -10,6 +10,12 @@ _private.redirectUrl = function redirectUrl(options) {
query = options.query,
parts = url.parse(redirectTo);
// CASE: ensure we always add a trailing slash to reduce the number of redirects
// e.g. you are redirected from example.com/ghost to admin.example.com/ghost and Ghost would detect a missing slash and redirect you to /ghost/
if (!path.match(/\/$/)) {
path += '/';
}
return url.format({
protocol: parts.protocol,
hostname: parts.hostname,

View file

@ -177,7 +177,7 @@ describe('UNIT: url redirects', function () {
req.originalUrl = '/ghost';
urlRedirects(req, res, next);
next.called.should.be.false();
res.redirect.calledWith(301, 'https://default.com:2368/ghost').should.be.true();
res.redirect.calledWith(301, 'https://default.com:2368/ghost/').should.be.true();
done();
});
@ -195,7 +195,7 @@ describe('UNIT: url redirects', function () {
req.originalUrl = '/ghost';
urlRedirects(req, res, next);
next.called.should.be.false();
res.redirect.calledWith(301, 'https://admin.default.com:2368/ghost').should.be.true();
res.redirect.calledWith(301, 'https://admin.default.com:2368/ghost/').should.be.true();
done();
});
@ -213,7 +213,7 @@ describe('UNIT: url redirects', function () {
req.originalUrl = '/blog/ghost';
urlRedirects(req, res, next);
next.called.should.be.false();
res.redirect.calledWith(301, 'https://admin.default.com:2368/blog/ghost').should.be.true();
res.redirect.calledWith(301, 'https://admin.default.com:2368/blog/ghost/').should.be.true();
req.secure = true;
host = 'admin.default.com:2368';
@ -240,7 +240,7 @@ describe('UNIT: url redirects', function () {
urlRedirects(req, res, next);
next.called.should.be.false();
res.redirect.calledWith(301, 'https://admin.default.com:2368/ghost?test=true').should.be.true();
res.redirect.calledWith(301, 'https://admin.default.com:2368/ghost/?test=true').should.be.true();
done();
});
@ -258,7 +258,7 @@ describe('UNIT: url redirects', function () {
req.originalUrl = '/ghost';
urlRedirects(req, res, next);
next.called.should.be.false();
res.redirect.calledWith(301, 'https://default.com:2368/ghost').should.be.true();
res.redirect.calledWith(301, 'https://default.com:2368/ghost/').should.be.true();
req.secure = true;
urlRedirects(req, res, next);