Released: RedirectManager for CMS 12 .net6
This .net 6 library contains a RedirectManager and admin user interface integration for Optimizely CMS 12 and commerce 14 projects.
Published 3 September 2022
Optimizely CMS 12.6 and Commerce 14
I’ve been using this redirect manager for 5 years now, it is simple and does the work very well. The project has been open source but never as an nuget addon. I have now upgraded it to .net 6 and CMS 12 AND it does exists as an installable package => https://nuget.optimizely.com/package/?id=Epicweb.Optimizely.RedirectManager
Open Source Project => https://github.com/Epicweb-Optimizely/Epicweb.Optimizely.RedirectManager
If you need the RedirectManager for CMS 11 use => https://github.com/huilaaja/RedirectManager
With the automatic redirect keeper, it saves a “Redirection rule” (or several for pages with subpages) when the editor moves a page or changes the url segment name.
Happy redirecting!
Features
- Easily create redirects to any URLs or to Optimizely CMS pages, products, images and documents.
- Wild card rules.
- Reordering and prioritizing rules.
- Multi-site and lang support.
- Allow moving and changing URLs of Optimizely CMS pages and the redirects still works.
- All redirects are HTTP 301 (Moved permanently), because search engines only follow this kind of redirects.
- Clean up rules functionality (duplicate rules remover)
- Access restrictions allow usage of rule manager to only administrators or redirectmanagers.
- And the most important: It’s open Source and it’s yours to extend and manipulate!
“Rules Clean up”
After years of use, the rules lists gets long, therefor I contributed with a button to clean up rules.
Gets the job done
- Remove duplicates
- Remove self pointing rules
- Removes deleted urls
Installation and configuration
Available on nuget.optimizely.com https://nuget.optimizely.com/package/?id=Epicweb.Optimizely.RedirectManager
How to get started?
Start by installing NuGet package:
Install-Package Epicweb.Optimizely.RedirectManager
Add to startup.cs
services.AddRedirectManager(
addQuickNavigator: true,
enableChangeEvent: true);
also
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//remember if you use env.IsDevelopment() do activate error pages in dev env too
//do NOT use => app.UseStatusCodePagesWithRedirects("/Error/{0}");//not redirects
app.UseStatusCodePagesWithReExecute("/Error/{0}");
app.UseExceptionHandler("/Error/500");
}
Run your application
First time, you will be prompted to create the redirect table “SEO_redirect”
Upgraded from .netFramework 4?
That should not be a problem. Make sure to change the name of the table to “SEO_redirect”, should be the same schema.
Add code to 404 handler
add this code into your error/404 custom page controller
#region RedirectManager
if (statusCode == 404)
{
string originalRelativePath = HttpContext.Request.GetRawUrl();//get current url
string redirectTo = _redirectService.GetPrimaryRedirectUrlOrDefault(SiteDefinition.Current.Name, originalRelativePath);//check if redirect rule exists
if (redirectTo != null)
{
Response.Redirect(redirectTo, true);
}
}
#endregion
Complete example of ErrorController
using Epicweb.Optimizely.RedirectManager;
using EPiServer.Web;
using Microsoft.AspNetCore.Mvc;
namespace Epicweb.Optimizely.Blog.Features.Error
{
public class ErrorController : Controller
{
private readonly IContentRepository _contentRepository;
private readonly RedirectService _redirectService;
public ErrorController(IContentRepository contentRepository, RedirectService redirectService)
{
_contentRepository = contentRepository;
_redirectService = redirectService;
}
[Route("/Error/{statusCode}")]
public IActionResult HttpStatusCodeHandler(int statusCode)
{
ViewBag.Code = statusCode;
//this is specific redirectManager
#region RedirectManager
if (statusCode == 404)
{
string originalRelativePath = HttpContext.Request.GetRawUrl();//get current url
string redirectTo = _redirectService.GetPrimaryRedirectUrlOrDefault(SiteDefinition.Current.Name, originalRelativePath);//check if redirect rule exists
if (redirectTo != null)
{
Response.Redirect(redirectTo, true);
}
}
#endregion
return View("~/Features/Error/Error.cshtml");
}
}
}
Roles and restrictions
Users with role WebAdmins and RedirectManagers will automatically see the menu in Optimizely CMS
About the author
Luc Gosso
– Independent Senior Web Developer
working with Azure and Optimizely
Twitter: @LucGosso
LinkedIn: linkedin.com/in/luc-gosso/
Github: github.com/lucgosso