fsasvari/laravel-trailing-slash
Composer 安装命令:
composer require fsasvari/laravel-trailing-slash
包简介
The package that adds redirection with trailing slash to Laravel framework.
README 文档
README
Adds url formatting and redirection with trailing slash to Laravel framework versions 12.x, 11.x, 10.x, 9.x, 8.x, 7.x, 6.x and 5.x.
Compatibility Chart
| Laravel Trailing Slash | Laravel | PHP |
|---|---|---|
| 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": "7.*"
Step 2: Service Provider
If you are using Laravel 11.x and above, register the LaravelTrailingSlash\RoutingServiceProvider in your bootstrap/providers.php configuration file:
return [ // Package Service Providers... // ... LaravelTrailingSlash\RoutingServiceProvider::class, // ... ],
If you are using Laravel 10.x and below, register the LaravelTrailingSlash\RoutingServiceProvider in your config/app.php configuration 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
Buy me a Beer
fsasvari/laravel-trailing-slash 适用场景与选型建议
fsasvari/laravel-trailing-slash 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 171.56k 次下载、GitHub Stars 达 61, 最近一次更新时间为 2017 年 01 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「url」 「router」 「redirect」 「uri」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fsasvari/laravel-trailing-slash 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fsasvari/laravel-trailing-slash 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fsasvari/laravel-trailing-slash 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy URL rewrites in your Laravel application
A Laravel helper to detect if the current route/path is active.
Router
Provides a service and twig extension for getting short urls like http://your.host/~short
PMVC App Action Router
Database alias router extension for Nette Framework
统计信息
- 总下载量: 171.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 61
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-01-25
