This library is available from NuGet.org.
A .NET Standard class library that provides predefined rewrite rules for ASP.net core.
See the changelog for changes and roadmap.
This adds a rewrite rule that redirects requests to a standardly formated URL. The is typically done for SEO purposes.
var options = new RewriteOptions().AddRedirectToCanonicalUrl();
app.UseRewriter(options);
A CanonicalUrlOptions
object can be passed to AddRedirectToCanonicalUrl
to customize how the redirection is handled. The following are the properties that are available.
This is a whitelist of host names other than the primary host name that will not be swapped for the primary host name. This could be used in load-balanced environments to allow a host name for individual servers.
By default, URLs with a file name extension will not have the canonical URL rules applied. However, the file name extensions in this list will have the rules applied. This list defaults to having common html file extensions in it (.html, .htm, .aspx, etc.).
A flag to indicate whether or not the URL should be lowercased. This defaults to true.
The host name to redirect to if the DNS host name does not match this and is not listed in AlternativeHosts
.
A flag to indicate whether the rules should be applied to any query string present.
The status code to return if a redirect is determined to be needed. This defaults to 301.
An enumeration value that determines what should be done with a trailing slash at the end of a URL.