tallieutallieu / dry-redirects
Dry Redirects
Requires
- tallieutallieu/dry: *
- tallieutallieu/dry-dbi: *
- tallieutallieu/oak: *
README
A URL redirection package for the Dry PHP framework. This package allows you to manage redirects through an admin interface and automatically handle URL redirections with parameter support.
Features
- Admin interface for managing redirects
- Support for 301 (permanent), 302 (temporary), and 404 (not found) redirects
- Parameter matching and substitution (e.g.,
/product/{id}
→/products/{id}
) - Redirect hit tracking and logging
- Database migrations for easy setup
Installation
Via Composer
composer require tallieutallieu/dry-redirects
Service Provider Registration
Add the service provider to your application:
// In your application's service provider registration $app->register(Tnt\Redirects\RedirectServiceProvider::class);
Database Migration
Run the database migrations to create the necessary tables:
php oak migration migrate
Usage
Creating Redirects
Navigate to the admin interface at /admin/redirects
and create redirects with:
- Source Path: The URL pattern to match (e.g.,
/old-path
or/product/{id}
) - Target Path: The destination URL (e.g.,
/new-path
or/products/{id}
) - Status Code: 301 (permanent), 302 (temporary), or 404 (not found)
- Active: Enable/disable the redirect
Parameter Substitution
You can use parameters in your redirects by enclosing them in curly braces:
- Source Path:
/product/{id}
- Target Path:
/products/{id}
When a user visits /product/123
, they will be redirected to /products/123
.
Redirect Logs
The system automatically logs all redirect hits. You can view these logs in the admin interface at /admin/redirects/redirect-logs
.
Under the Hood
The package works by:
- Loading all active redirects from the database at application boot
- Registering dynamic routes for each redirect
- When a redirect is triggered:
- Parameters are extracted and substituted
- A
RouteWasHit
event is dispatched (for logging) - The user is redirected to the target URL with the appropriate status code
Administration
The admin interface provides two main sections:
- Redirects: Create, edit, and delete redirects
- Redirect Logs: View and manage redirect hit logs
Requirements
- tallieutallieu/dry: ^v3.1.0
- tallieutallieu/oak: dev-php8.2
License
This package is proprietary software developed by Tallieu & Tallieu.