praman-codelab/self-healing-url

Laravel package for self-healing URLs: typo correction, normalization, smart fallback.

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/praman-codelab/self-healing-url

dev-main 2025-09-30 09:57 UTC

This package is not auto-updated.

Last update: 2026-01-07 09:49:40 UTC


README

Automatically normalizes URLs and fixes common typos in Laravel applications.

Features

  • Normalize URLs (lowercase, remove trailing slash)
  • Fuzzy redirects for static routes
  • Corrects parameterized routes
  • SEO-friendly 301 redirects
  • Configurable Levenshtein thresholds

Installation

Require the package via Composer:

composer require praman-codelab/self-healing-url:dev-main

Note: During development, you can use dev-main. For stable releases, replace with a version tag (e.g., ^1.0).

Middleware Setup

Add the middleware to app/Http/Kernel.php under the web group:

protected $middlewareGroups = [
    'web' => [
        \Bala\SelfHealingUrl\Middleware\NormalizeUrl::class,
        // other middlewares...
    ],
];

This ensures URLs are normalized before routing.

Config

Publish the package configuration:

php artisan vendor:publish --tag=config

Then adjust thresholds in config/selfhealing.php:

return [
    'static_distance' => 3, // max typo distance for static routes
    'param_distance' => 2,  // max typo distance for parameterized routes
];

Usage Examples

  • Misspelled static URL:
/abut-us → /about-us
  • Misspelled parameterized URL:
/produts/123 → /products/123
  • If no close match is found, Laravel returns a standard 404 page.

License

MIT

Publishing Steps for Packagist

  1. Create a GitHub repository and push your package folder.
  2. Tag a stable version:
git tag v1.0.0
git push origin v1.0.0
  1. Submit your repository to Packagist.org.
  2. Optionally, set up the GitHub webhook for automatic updates:
  • Payload URL: https://packagist.org/api/github?username=YOUR_PACKAGIST_USERNAME
  • Content Type: application/json
  • Secret: your Packagist API token
  • Events: push events only