diff --git a/core/frontend/apps/amp/index.js b/core/frontend/apps/amp/index.js index 416b121dbb..5b60a3dc82 100644 --- a/core/frontend/apps/amp/index.js +++ b/core/frontend/apps/amp/index.js @@ -1,16 +1,17 @@ -const router = require('./lib/router'), - registerHelpers = require('./lib/helpers'), - urlUtils = require('../../../server/lib/url-utils'), +const router = require('./lib/router'); +const registerHelpers = require('./lib/helpers'); +const urlUtils = require('../../../server/lib/url-utils'); - // Dirty requires - settingsCache = require('../../../server/services/settings/cache'); +// Dirty requires +const settingsCache = require('../../../server/services/settings/cache'); function ampRouter(req, res) { if (settingsCache.get('amp') === true) { return router.apply(this, arguments); } else { // routeKeywords.amp: 'amp' - let redirectUrl = req.originalUrl.replace(/amp\/$/, ''); + let redirectUrl = req.originalUrl.replace(/\/amp\//, '/'); + urlUtils.redirect301(res, redirectUrl); } } diff --git a/core/test/regression/site/frontend_spec.js b/core/test/regression/site/frontend_spec.js index e8ea49d435..c4da7047ca 100644 --- a/core/test/regression/site/frontend_spec.js +++ b/core/test/regression/site/frontend_spec.js @@ -262,6 +262,20 @@ describe('Frontend Routing', function () { .expect(301) .end(doEnd(done)); }); + + it('should redirect to regular post with query params when AMP is disabled', function (done) { + sinon.stub(settingsCache, 'get').callsFake(function (key, options) { + if (key === 'amp' && !options) { + return false; + } + return origCache.get(key, options); + }); + + request.get('/welcome/amp/?q=a') + .expect('Location', '/welcome/?q=a') + .expect(301) + .end(doEnd(done)); + }); }); describe('Static assets', function () {