This .net 6 library contains a RedirectManager and admin user interface integration in an Optimizely CMS 12 and commerce 14 project. Tested with Alloy.
An Optimizely addon that helps with managements of redirects. Simple but yet so effective. It is based out of https://github.com/huilaaja/RedirectManager
**This is the .net 6 version of : https://github.com/huilaaja/RedirectManager ** <-- use this for CMS 11
Preview:
- 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 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!
Preview:
Available on nuget.optimizely.com https://nuget.optimizely.com/package/?id=Epicweb.Optimizely.RedirectManager
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"
That should not be a problem. If you used the Solita solution, change the name of the table "SOLITA_Redirect" to "SEO_Redirect", should be the same schema if you run on latest solution, make sure you have run this V2 upgrade before, (or added the host column manually) [https://github.com/huilaaja/RedirectManager/blob/c7ec6ea4b12aa36b53b27fa89bb373286fe0d53d/WebProject/Redirects/RedirectService.cs#L282]
Schema should look like this:
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
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");
}
}
}
Users with role WebAdmins and RedirectManagers will automatically see the menu in Optimizely CMS
Get this solution runing
-
Clone it
-
Unpack the /alloy/app_data/blobs-and-database.zip
-
dotnet run
-
log in to CMS with "admin" and "Test1234!"