From c022d8ec5b974fa7542a12f6157a3adbf879b464 Mon Sep 17 00:00:00 2001 From: Dan Jensen Date: Tue, 29 Aug 2023 09:45:00 -0500 Subject: [PATCH] Set trailingSlash: true for @site.url Ghost policy is to add a trailing slash to all URLs generated. However, it was not doing that for @site.url. That created a problem for Ghost installations at subdirectories, because requests to the generated URL like example.com/blog would be redirected by Ghost to the trailing-slash version like example.com/blog/. That redirect harmed SEO. This replaces trailingSlash: false with trailingSlash: true in the @site.url generation. Now Ghost complies with it's trailing slash policy and avoids creating an unnecessary, SEO-harming redirect. --- .../theme-engine/middleware/update-local-template-options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ghost/core/core/frontend/services/theme-engine/middleware/update-local-template-options.js b/ghost/core/core/frontend/services/theme-engine/middleware/update-local-template-options.js index c0f970134f..616d135850 100644 --- a/ghost/core/core/frontend/services/theme-engine/middleware/update-local-template-options.js +++ b/ghost/core/core/frontend/services/theme-engine/middleware/update-local-template-options.js @@ -9,7 +9,7 @@ function updateLocalTemplateOptions(req, res, next) { // adjust @site.url for http/https based on the incoming request const siteData = { - url: urlUtils.urlFor('home', {trailingSlash: false}, true) + url: urlUtils.urlFor('home', {trailingSlash: true}, true) }; // @TODO: it would be nicer if this was proper middleware somehow...