Rehman.Slugify 2.0.0

dotnet add package Rehman.Slugify --version 2.0.0
                    
NuGet\Install-Package Rehman.Slugify -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rehman.Slugify" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rehman.Slugify" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Rehman.Slugify" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Rehman.Slugify --version 2.0.0
                    
#r "nuget: Rehman.Slugify, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Rehman.Slugify@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Rehman.Slugify&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Rehman.Slugify&version=2.0.0
                    
Install as a Cake Tool

Rehman.Slugify — Enterprise SEO & URL Management Toolkit for .NET

License: MIT .NET

A lightweight yet powerful .NET library for SEO-friendly slug generation and a full Enterprise SEO Automation Toolkit.
Covers slugs, metadata, structured data (JSON-LD), sitemaps, robots.txt, redirect management, ASP.NET Core middleware, caching, and SEO auditing — all in one package.


Table of Contents


Overview

Rehman.Slugify v2 is a drop-in upgrade from v1. Every existing method signature is preserved. No breaking changes.
On top of the original slug utilities, v2 ships a complete SEO automation layer designed for real-world CMS, blog, and e-commerce applications.


Features

Feature Class / Method
Text → SEO slug SlugHelper.ToSlug
Slug → Title Case SlugHelper.FromSlug
Slug validation SlugHelper.IsSlugValid
Batch slugify SlugHelper.BatchSlugify
Unique slug with counter SlugHelper.UniqueSlugify
SEO meta title / description / keywords SeoMetadataManager
Open Graph tags SeoMetadataManager.ToHtml
Article / Product / Organization / Breadcrumb JSON-LD SchemaGenerator
XML Sitemap SitemapGenerator
robots.txt RobotsManager
Slug history tracking RedirectManager
Auto 301/302 redirects on slug change RedirectManager
End-to-end SEO automation SeoEngine
Duplicate slug detection SeoAuditTools
Metadata & slug best-practice audit SeoAuditTools
ASP.NET Core middleware SlugRedirectMiddleware
In-memory caching IMemoryCache integration

Installation

dotnet add package Rehman.Slugify

Or via the NuGet Package Manager:

Install-Package Rehman.Slugify

Framework Compatibility

Framework Supported
.NET Framework 4.6.1+ ✅
.NET Standard 2.0 ✅
.NET Core 3.1 ✅
.NET 6 ✅
.NET 8 ✅

Quick Start

using Rehman.Slugify;
using Rehman.Slugify.Seo;

// --- Slugs (v1 API — unchanged) ---
var slug = SlugHelper.ToSlug("C# Enterprise Guide!");       // "c-sharp-enterprise-guide"
var title = SlugHelper.FromSlug("c-sharp-enterprise-guide"); // "C Sharp Enterprise Guide"
var valid = SlugHelper.IsSlugValid("hello-world");           // true
var unique = SlugHelper.UniqueSlugify("Hello", new[] { "hello" }); // "hello-1"

// --- SEO Engine (v2 API) ---
var engine = new SeoEngine("https://mysite.com", new SeoMetadataOptions
{
    SiteName = "My Site",
    BaseUrl  = "https://mysite.com"
});

var page = engine.Process(new ContentItem
{
    Title      = "Getting Started with ASP.NET Core",
    Body       = "This post walks you through...",
    AuthorName = "Muhammad Rehman Tahir"
});

Console.WriteLine(page.Slug);                          // "getting-started-with-asp-net-core"
Console.WriteLine(page.Metadata.Description);          // auto-generated
Console.WriteLine(page.ArticleSchemaScript);           // <script type="application/ld+json">...
Console.WriteLine(engine.Sitemap.Generate());          // <?xml version="1.0"...
Console.WriteLine(engine.Robots.Generate());           // User-agent: *...

Core Slug API

All original v1 method signatures are unchanged.

ToSlug

string ToSlug(string input, char separator = '-', int? maxLength = null, bool lowerCase = true)
SlugHelper.ToSlug("Hello World!")          // "hello-world"
SlugHelper.ToSlug("C# Guide")             // "c-sharp-guide"
SlugHelper.ToSlug("Résumé Café")          // "resume-cafe"
SlugHelper.ToSlug("50% Off Sale")         // "50-percent-off-sale"
SlugHelper.ToSlug("A & B")               // "a-and-b"
SlugHelper.ToSlug("Title", maxLength: 10) // respects word boundary
SlugHelper.ToSlug("Title", separator: '_')// "title"

Enhanced symbol map (v2): &, #, @, %, +, =, ~, >, <, ©, ®, ™, €, £, $, ¥

FromSlug

string FromSlug(string slug, char separator = '-')
SlugHelper.FromSlug("this-is-title") // "This Is Title"
SlugHelper.FromSlug("hello_world", '_') // "Hello World"

IsSlugValid

bool IsSlugValid(string input, char separator = '-')
SlugHelper.IsSlugValid("hello-world")   // true
SlugHelper.IsSlugValid("Hello World!")  // false
SlugHelper.IsSlugValid("-bad-slug-")    // false

BatchSlugify

IEnumerable<string> BatchSlugify(IEnumerable<string> inputs, char separator = '-', int? maxLength = null, bool lowerCase = true)
var slugs = SlugHelper.BatchSlugify(new[] { "First Post", "C# Tips", "Résumé Guide" });
// ["first-post", "c-sharp-tips", "resume-guide"]

UniqueSlugify

string UniqueSlugify(string titleOrSlug, IEnumerable<string> existing, char separator = '-')
var existing = new[] { "hello-world", "hello-world-1" };
SlugHelper.UniqueSlugify("Hello World", existing); // "hello-world-2"

SEO Metadata Manager

var options = new SeoMetadataOptions
{
    SiteName             = "My Blog",
    BaseUrl              = "https://myblog.com",
    MaxTitleLength       = 60,
    MaxDescriptionLength = 160
};

var manager = new SeoMetadataManager(options);

// Auto-generate from title + body
var meta = manager.Generate("My Blog Post", "Full article body text...");

// Manual overrides
var overridden = manager.Generate("Post", bodyContent, new SeoMetadata
{
    Title    = "Custom SEO Title",
    OgImage  = "https://cdn.example.com/post.jpg",
    Robots   = "index, follow"
});

// Render as HTML
string html = manager.ToHtml(meta);
// <title>My Blog Post | My Blog</title>
// <meta name="description" content="..." />
// <meta name="keywords" content="..." />
// <meta name="robots" content="index, follow" />
// <link rel="canonical" href="https://myblog.com/my-blog-post" />
// <meta property="og:title" content="..." />
// <meta property="og:description" content="..." />

Structured Data (Schema / JSON-LD)

Article

var script = SchemaGenerator.Article(new ArticleSchema
{
    Headline      = "Enterprise SEO in .NET",
    AuthorName    = "Muhammad Rehman Tahir",
    PublisherName = "Rehman Blog",
    PublisherLogo = "https://example.com/logo.png",
    ImageUrl      = "https://example.com/article.jpg",
    Url           = "https://example.com/enterprise-seo",
    DatePublished = DateTime.UtcNow,
    DateModified  = DateTime.UtcNow
});
// Outputs: <script type="application/ld+json">{ "@type": "Article", ... }</script>

Product

var script = SchemaGenerator.Product(new ProductSchema
{
    Name         = "Premium Widget",
    Price        = 49.99m,
    Currency     = "USD",
    Brand        = "ACME",
    Sku          = "WDG-001",
    Availability = "InStock",
    RatingValue  = 4.8,
    ReviewCount  = 256
});

Organization

var script = SchemaGenerator.Organization(new OrganizationSchema
{
    Name    = "ACME Corp",
    Url     = "https://acme.com",
    LogoUrl = "https://acme.com/logo.png",
    Email   = "hello@acme.com",
    SameAs  = new List<string>
    {
        "https://twitter.com/acme",
        "https://linkedin.com/company/acme"
    }
});
var script = SchemaGenerator.Breadcrumb(new List<BreadcrumbItem>
{
    new() { Name = "Home", Url = "https://example.com" },
    new() { Name = "Blog", Url = "https://example.com/blog" },
    new() { Name = "Post", Url = "https://example.com/blog/post" }
});

Sitemap Generator

var sitemap = new SitemapGenerator("https://example.com")
    .Add("/",           DateTime.UtcNow, SitemapChangeFreq.Daily,   1.0)
    .Add("blog",        DateTime.UtcNow, SitemapChangeFreq.Daily,   0.9)
    .Add("blog/post-1", DateTime.UtcNow, SitemapChangeFreq.Weekly,  0.7)
    .Add("about",       DateTime.UtcNow, SitemapChangeFreq.Monthly, 0.5);

string xml = sitemap.Generate();

Output:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://example.com/blog/post-1</loc>
    <lastmod>2024-06-15</lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.7</priority>
  </url>
  ...
</urlset>

Robots.txt Manager

var robots = new RobotsManager()
    .Allow("/public")
    .Disallow("/admin")
    .Disallow("/private")
    .Disallow("/", "Bingbot")   // block Bing entirely
    .SetSitemap("https://example.com/sitemap.xml");

string content = robots.Generate();

Output:

# Generated by Rehman.Slugify
User-agent: *
Allow: /public
Disallow: /admin
Disallow: /private

User-agent: Bingbot
Disallow: /

Sitemap: https://example.com/sitemap.xml

Slug History & Redirect Manager

var redirects = new RedirectManager();

// Create a page
redirects.RegisterSlugChange("post-1", "my-first-post");

// Rename it — a 301 redirect is automatically created
redirects.RegisterSlugChange("post-1", "my-updated-post-title");

// Rename again — all previous redirects are chained automatically
redirects.RegisterSlugChange("post-1", "final-post-title");

// Resolve old slug
var redirect = redirects.Resolve("my-first-post");
// redirect.NewSlug  == "final-post-title"
// redirect.Type     == RedirectType.Permanent (301)

// View full history
var history = redirects.GetHistory("post-1");

// All registered redirects
var all = redirects.GetAllRedirects();

SEO Automation Engine

The SeoEngine is the high-level orchestrator. Calling Process() on a ContentItem atomically:

  1. Generates a unique slug
  2. Registers slug history (enables auto-redirects on future updates)
  3. Auto-generates SEO metadata
  4. Generates Article JSON-LD schema
  5. Appends the page to the sitemap
  6. Optionally runs an SEO audit
var engine = new SeoEngine("https://example.com", new SeoMetadataOptions
{
    SiteName = "My Site",
    BaseUrl  = "https://example.com"
});

// Configure robots.txt
engine.Robots
    .Disallow("/admin")
    .Disallow("/api");

// Process a content item
var result = engine.Process(new ContentItem
{
    EntityId   = "article-42",
    Title      = "10 Tips for ASP.NET Core Performance",
    Body       = "In this post we explore...",
    AuthorName = "Muhammad Rehman Tahir",
    ImageUrl   = "https://example.com/images/perf.jpg",
    PublishedAt = DateTime.UtcNow
});

Console.WriteLine(result.Slug);                    // "10-tips-for-asp-net-core-performance"
Console.WriteLine(result.Metadata.Title);          // "10 Tips for ASP.NET Core Performance | My Site"
Console.WriteLine(result.Metadata.CanonicalUrl);   // "https://example.com/10-tips-for-asp-net-core-performance"
Console.WriteLine(result.AuditResult?.IsValid);    // true / false with Errors, Warnings, Suggestions

// Serve sitemap and robots
string sitemapXml = engine.Sitemap.Generate();
string robotsTxt  = engine.Robots.Generate();

SEO Audit Tools

// Audit a single slug
var slugAudit = SeoAuditTools.AuditSlug("Hello World!");
// slugAudit.IsValid   == false
// slugAudit.Errors    == ["Slug contains invalid characters..."]

// Audit SEO metadata
var metaAudit = SeoAuditTools.AuditMetadata(meta);
// metaAudit.IsValid     == true / false
// metaAudit.Errors      => critical issues (missing title, missing description)
// metaAudit.Warnings    => length violations
// metaAudit.Suggestions => canonical URL, OG image

// Detect duplicate slugs in a list
var dupes = SeoAuditTools.FindDuplicateSlugs(new[] { "slug-a", "slug-b", "slug-a" });
// dupes == ["slug-a"]

// Detect duplicates with entity mapping
var pairs = new[]
{
    new KeyValuePair<string, string>("post-1", "hello-world"),
    new KeyValuePair<string, string>("post-2", "hello-world")
};
var dupeReport = SeoAuditTools.FindDuplicates(pairs);
// dupeReport[0].Slug        == "hello-world"
// dupeReport[0].Occurrences == ["post-1", "post-2"]

ASP.NET Core Integration

Service Registration

// Program.cs
using Rehman.Slugify.AspNetCore;

builder.Services.AddRehmanSlugify(
    baseUrl: "https://mysite.com",
    metaOptions: new SeoMetadataOptions
    {
        SiteName = "My Site",
        BaseUrl  = "https://mysite.com"
    },
    middlewareOptions: new SlugMiddlewareOptions
    {
        CacheDuration = TimeSpan.FromMinutes(15)
    }
);

Middleware Pipeline

app.UseRehmanSlugify(); // must be early in the pipeline

The middleware automatically:

  • Serves GET /sitemap.xml → XML sitemap
  • Serves GET /robots.txt → robots.txt
  • Issues 301/302 redirects for any old slugs registered in RedirectManager
  • Caches redirect resolutions in IMemoryCache

Injecting the SeoEngine

app.MapPost("/articles", (CreateArticleRequest req, SeoEngine engine) =>
{
    var result = engine.Process(new ContentItem
    {
        Title = req.Title,
        Body  = req.Body
    });

    return Results.Ok(new
    {
        slug     = result.Slug,
        metadata = result.Metadata,
        schema   = result.ArticleSchemaScript
    });
});

Controller Example (MVC)

public class ArticlesController : Controller
{
    private readonly SeoEngine _seo;

    public ArticlesController(SeoEngine seo) => _seo = seo;

    [HttpPost]
    public IActionResult Create(CreateArticleViewModel model)
    {
        var result = _seo.Process(new ContentItem
        {
            EntityId = model.Id,
            Title    = model.Title,
            Body     = model.Body
        });

        ViewBag.MetaHtml = new SeoMetadataManager()
            .ToHtml(result.Metadata);

        return View("Success", result);
    }
}

Caching

Redirect resolution is cached automatically when IMemoryCache is registered (included in AddRehmanSlugify).

To configure cache duration:

builder.Services.AddRehmanSlugify("https://example.com",
    middlewareOptions: new SlugMiddlewareOptions
    {
        CacheDuration = TimeSpan.FromHours(1)   // set null to disable
    });

Changelog

v2.0.0

  • New: SeoMetadataManager — auto-generate and override SEO metadata
  • New: SchemaGenerator — Article, Product, Organization, Breadcrumb JSON-LD
  • New: SitemapGenerator — dynamic XML sitemaps with frequency and priority
  • New: RobotsManager — fluent robots.txt generation
  • New: RedirectManager — slug history, auto-301/302 on slug changes, chain updates
  • New: SeoEngine — end-to-end automation engine
  • New: SeoAuditTools — metadata audit, slug audit, duplicate detection
  • New: SlugRedirectMiddleware — ASP.NET Core middleware
  • New: AddRehmanSlugify / UseRehmanSlugify extension methods
  • Enhanced: ToSlug symbol replacement table (%, +, =, ~, >, <, ©, ®, ™, €, £, $, ¥)
  • Enhanced: ToSlug max-length truncates at word boundaries
  • Compatibility: All v1 method signatures preserved — zero breaking changes

v1.0.0

  • ToSlug, FromSlug, IsSlugValid, BatchSlugify, UniqueSlugify

Author

Muhammad Rehman Tahir
MIT License © 2025

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 180 4/18/2026
1.0.0 295 9/10/2025