fsasvari / laravel-trailing-slash
The package that adds redirection with trailing slash to Laravel framework.
Package info
github.com/fsasvari/laravel-trailing-slash
pkg:composer/fsasvari/laravel-trailing-slash
Requires
- php: ^8.3
- illuminate/routing: ^13
Requires (Dev)
- illuminate/database: ^13
- laravel/pint: ^1.32
- mockery/mockery: ^1.6
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^12.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- v8.0.1
- v8.0.0
- v7.0.1
- v7.0.0
- v6.1.1
- v6.1.0
- v6.0.0
- v5.0.0
- v4.0.0
- v3.0.0
- v2.0.2
- v2.0.1
- v2.0.0
- v1.1.0
- v1.0.2
- v1.0.1
- v1.0.0
- v0.3.4
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3
- v0.2.1
- v0.2.0
- v0.1.12
- v0.1.11
- v0.1.10
- v0.1.9
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- dev-analysis-OLR5OP
- dev-cleanup-and-ai-agents
- dev-l13-compatibility
- dev-analysis-EEQ5GD
This package is auto-updated.
Last update: 2026-09-17 10:51:43 UTC
README
Adds url formatting and redirection with trailing slash to Laravel framework versions 13.x, 12.x, 11.x, 10.x, 9.x, 8.x, 7.x, 6.x and 5.x.
Compatibility Chart
| Laravel Trailing Slash | Laravel | PHP |
|---|---|---|
| 8.x | 13.x | 8.3+ |
| 7.x | 12.x | 8.2+ |
| 6.x | 11.x | 8.2+ |
| 5.x | 10.x | 8.1+ |
| 4.x | 9.x | 8.0.2+ |
| 3.x | 8.x | 7.3+/8.0+ |
| 2.x | 7.x | 7.3+ |
| 1.x | 6.x | 7.2+ |
| 0.3.x | 5.7-5.8 | 7.1.3+ |
| 0.2.x | 5.6 | 7.1.3+ |
| 0.1.x | 5.5 | 7.0.0+ |
Installation
Step 1: Install package
To get started with Laravel Trailing Slash, use Composer command to add the package to your composer.json project's dependencies:
composer require fsasvari/laravel-trailing-slash
Or add it directly by copying next line into composer.json:
"fsasvari/laravel-trailing-slash": "8.*"
Step 2: Service Provider
Laravel automatically discovers this package via package auto-discovery, so manual registration is usually not required.
If you have disabled auto-discovery or prefer manual registration:
- For
Laravel 11.xand above, register theLaravelTrailingSlash\RoutingServiceProviderin yourbootstrap/providers.phpconfiguration file:
return [ // Package Service Providers... // ... LaravelTrailingSlash\RoutingServiceProvider::class, // ... ];
- For
Laravel 10.xand below, register theLaravelTrailingSlash\RoutingServiceProviderin yourconfig/app.phpconfiguration file:
'providers' => [ // Application Service Providers... // ... // Package Service Providers... // ... LaravelTrailingSlash\RoutingServiceProvider::class, // ... ],
Step 3: .htaccess
If you are using apache, copy following redirection code from public/.htaccess to your own project:
<IfModule mod_rewrite.c>
# Redirect To Trailing Slashes If Not A Folder Or A File...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
</IfModule>
Step 4: Routes
In routes/web.php, you must use routes with trailing slashes now:
Route::get('/', function () { return view('welcome'); }); Route::get('about/', function () { return view('about'); }); Route::get('contact/', function () { return view('contact'); });
Usage
Every time you use some Laravel redirect function, trailing slash ("/") will be applied at the end of url.
return redirect('about/'); return back()->withInput(); return redirect()->route('text', ['id' => 1]); return redirect()->action('IndexController@about');
Change log
Please see CHANGELOG for more information what has changed recently.
Notice
There is a problem with overriding Laravel Paginator and LengthAwarePaginator classes. So, every time you use paginate() method on your models, query builders etc., you must set current path for pagination links. Example:
$texts = Text::where('is_active', 1)->paginate(); $texts->setPath(URL::current()); $texts->links();
Licence
MIT Licence. Refer to the LICENSE file to get more info.
Author
Frano Šašvari
Email: sasvari.frano@gmail.com
