PHPackages                             watson/canonical - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. watson/canonical

ActiveLibrary[HTTP &amp; Networking](/categories/http)

watson/canonical
================

Canonical host middleware for Laravel

1.0.0(8y ago)33601MITPHPPHP &gt;=7.0.0

Since Aug 17Pushed 5y ago2 watchersCompare

[ Source](https://github.com/dwightwatson/canonical)[ Packagist](https://packagist.org/packages/watson/canonical)[ RSS](/packages/watson-canonical/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

Canonical, a simple host redirector for Laravel
===============================================

[](#canonical-a-simple-host-redirector-for-laravel)

Need your Laravel app to redirect from the root domain to `www.` or the other way around? Need your Laravel app to redirect all visitors to a HTTPS connection?

This is a small library for Laravel that provides a simple middleware that provides basic redirects for Laravel apps. You simply set the canonical host for your app and whether you want requests to be secured by default and Canonical will handle the rest.

This prevents duplicate content by ensuring that all visitors to your site are redirected to the correct host and upgraded to a secure connection if available.

You can configure this sort of stuff up in your web server as well, but there is an ease to keeping it inside your app so it's all kept in the same place.

Installation
------------

[](#installation)

First run `composer require watson/canonical`.

Next, add `Watson\Canonical\CanonicalMiddleware` to your `app/Http/Kernel.php` file where you'd like it to run.

Please note that Canonical only supports Laravel 5.5 at this time.

Configuration
-------------

[](#configuration)

You can configure Canonical through environment variables or by publishing the configuration file to your app with `php artisan vendor:publish --tags=config`.

Take a look at the configuration file that was created for you, `config/canonical.php`. Here you can set the default host name that you want to use for your app.

If your app receives a request from another host it will perform a permanent redirect to the canonical host you've set here, keeping the request path.

You can also opt to secure all requests too, so an insecure request will automatically be redirects to HTTPS if your site supports it.

Finally you are able to opt-out certain hosts if you don't want to redirect them - for example, an `api.` subdomain. Add any domains you wish to the `ignore` array.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3240d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1100408?v=4)[Dwight Watson](/maintainers/dwightwatson)[@dwightwatson](https://github.com/dwightwatson)

---

Top Contributors

[![dwightwatson](https://avatars.githubusercontent.com/u/1100408?v=4)](https://github.com/dwightwatson "dwightwatson (12 commits)")

---

Tags

canonical-urlslaravelphplaravelcanonicalredirector

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/watson-canonical/health.svg)

```
[![Health](https://phpackages.com/badges/watson-canonical/health.svg)](https://phpackages.com/packages/watson-canonical)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M341](/packages/psalm-plugin-laravel)[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k108.5M851](/packages/laravel-socialite)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.5k55.4M8.0k](/packages/larastan-larastan)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M135](/packages/laravel-mcp)[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k55.0M606](/packages/laravel-scout)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M129](/packages/laravel-pulse)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
