PHPackages                             afea/filament-redirect - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. afea/filament-redirect

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

afea/filament-redirect
======================

Redirect module for the Afea Filament CMS package ecosystem: 301/302 URL redirects with bulk CSV import and hit tracking.

v0.1.0(1mo ago)014↑445.5%MITPHPPHP ^8.4

Since Apr 21Pushed 1mo agoCompare

[ Source](https://github.com/AfeaSoftware/filament-redirect)[ Packagist](https://packagist.org/packages/afea/filament-redirect)[ RSS](/packages/afea-filament-redirect/feed)WikiDiscussions main Synced 1w ago

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

afea/filament-redirect
======================

[](#afeafilament-redirect)

Redirect module for the Afea Filament CMS package ecosystem.

Ships:

- `Redirect` model — source/target URL, 301/302/303/307/308, hit tracking
- `RedirectStatusCode` enum with HasLabel + HasColor
- `HandleRedirects` middleware — intercepts GET/HEAD requests and serves 301/302 responses from the database
- Filament v4 `RedirectResource` with CSV bulk import
- `RedirectPlugin` for panel registration
- `afea:install:redirect` installer

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

[](#installation)

```
composer require afea/filament-redirect
php artisan afea:install:redirect
```

Register in `AdminPanelProvider`:

```
->plugin(\Afea\Cms\Redirect\Filament\RedirectPlugin::make())
```

Register the middleware in `bootstrap/app.php`:

```
$middleware->web(append: [
    \Afea\Cms\Redirect\Http\Middleware\HandleRedirects::class,
]);
```

CSV import format
-----------------

[](#csv-import-format)

```
source_url,target_url,status_code,is_active
/old-page,https://example.com/new-page,301,1
/legacy/blog/*,https://example.com/blog,302,1
```

Aliases: `from`/`source`, `to`/`target`, `code`/`status`, `active`. `status_code` defaults to 301 and `is_active` to 1. Duplicate `source_url` rows update the existing rule in place.

Three common scenarios
----------------------

[](#three-common-scenarios)

### 1. Disable hit tracking on high-traffic sites

[](#1-disable-hit-tracking-on-high-traffic-sites)

Set `AFEA_REDIRECT_TRACK_HITS=false`. Saves one write per matched request.

### 2. Seed redirects from a migration

[](#2-seed-redirects-from-a-migration)

```
use Afea\Cms\Redirect\Models\Redirect;

Redirect::query()->insert([
    ['source_url' => '/eski-blog', 'target_url' => '/blog', 'status_code' => 301, 'is_active' => true, 'hit_count' => 0, 'created_at' => now(), 'updated_at' => now()],
]);
```

### 3. Override the model to add a scope

[](#3-override-the-model-to-add-a-scope)

```
class Redirect extends \Afea\Cms\Redirect\Models\Redirect
{
    public function scopeStale(Builder $q): Builder
    {
        return $q->where('last_used_at', '
