Skip to content

Commit 0edab34

Browse files
committed
Merge branch 'feature/canonical-redirect' into develop
Ensures that web requests are always redirected to the same casing as used in the topic graph. This helps ensure that there's alignment in the URL used in the browser, in the `SitemapController`, in the canonical URL, in search indexes, and in any reporting tools. In turn, that helps prevent issues with performance or reporting caused by some tools—such as Google Search Console or Google Analytics—interpreting two URLs that vary only by case as distinct URLs.
2 parents 69dff49 + 94b3a0d commit 0edab34

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

OnTopic.AspNetCore.Mvc/ValidateTopicAttribute.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ public override void OnActionExecuting(ActionExecutingContext filterContext) {
140140
return;
141141
}
142142

143+
/*------------------------------------------------------------------------------------------------------------------------
144+
| Handle canonical URL
145+
>-------------------------------------------------------------------------------------------------------------------------
146+
| Most search engines are case sensitive, even though many web servers are configured case insensitive. To help avoid
147+
| mismatches between the requested URL and the canonical URL, and to help ensure that references to topics maintain the
148+
| same case as assigned in the topic graph, URLs that vary only by case will be redirected to the expected case.
149+
\-----------------------------------------------------------------------------------------------------------------------*/
150+
if (!currentTopic.GetWebPath().Equals(filterContext.HttpContext.Request.Path, StringComparison.Ordinal)) {
151+
filterContext.Result = controller.RedirectPermanent(currentTopic.GetWebPath());
152+
return;
153+
}
154+
143155
/*------------------------------------------------------------------------------------------------------------------------
144156
| Base processing
145157
\-----------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)