在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):spatie/laravel-missing-page-redirector开源软件地址(OpenSource Url):https://github.com/spatie/laravel-missing-page-redirector开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Redirect missing pages in your Laravel applicationWhen transitioning from a old site to a new one your URLs may change. If your old site was popular you probably want to retain your SEO worth. One way of doing this is by providing permanent redirects from your old URLs to your new URLs. This package makes that process very easy. When installed you only need to add your redirects to the config file. Want to use the database as your source of redirects? No problem! Support usWe invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products. We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall. InstallationYou can install the package via composer: composer require spatie/laravel-missing-page-redirector The package will automatically register itself. Next you must register the //app/Http/Kernel.php
protected $middleware = [
...
\Spatie\MissingPageRedirector\RedirectsMissingPages::class,
], Finally you must publish the config file: php artisan vendor:publish --provider="Spatie\MissingPageRedirector\MissingPageRedirectorServiceProvider" This is the contents of the published config file: return [
/*
* This is the class responsible for providing the URLs which must be redirected.
* The only requirement for the redirector is that it needs to implement the
* `Spatie\MissingPageRedirector\Redirector\Redirector`-interface
*/
'redirector' => \Spatie\MissingPageRedirector\Redirector\ConfigurationRedirector::class,
/*
* By default the package will only redirect 404s. If you want to redirect on other
* response codes, just add them to the array. Leave the array empty to redirect
* always no matter what the response code.
*/
'redirect_status_codes' => [
\Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND
],
/*
* When using the `ConfigurationRedirector` you can specify the redirects in this array.
* You can use Laravel's route parameters here.
*/
'redirects' => [
// '/non-existing-page' => '/existing-page',
// '/old-blog/{url}' => '/new-blog/{url}',
],
]; UsageCreating a redirect is easy. You just have to add an entry to the 'redirects' => [
'/non-existing-page' => '/existing-page',
], You may use route parameters like you're used to when using Laravel's routes: 'redirects' => [
'/old-blog/{url}' => '/new-blog/{url}',
], Optional parameters are also... an option: 'redirects' => [
'/old-blog/{url?}' => '/new-blog/{url}',
], Finally, you can use an asterix ( 'redirects' => [
'/old-blog/*' => '/new-blog/{wildcard}', // {wilcard} will be the entire path
], By default the package only redirects if the request has a 'redirect_status_codes' => [\Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND], It is also possible to optionally specify which http response code is used when performing the redirect. By default the 'redirects' => [
'old-page' => ['/new-page', 302],
], EventsThe package will fire a Creating your own redirectorBy default this package will use the A valid redirector is any class that implements the namespace Spatie\MissingPageRedirector\Redirector;
use Symfony\Component\HttpFoundation\Request;
interface Redirector
{
public function getRedirectsFor(Request $request): array;
} The ChangelogPlease see CHANGELOG for more information what has changed recently. Testing$ composer test ContributingPlease see CONTRIBUTING for details. SecurityIf you've found a bug regarding security please mail [email protected] instead of using the issue tracker. CreditsLicenseThe MIT License (MIT). Please see License File for more information. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论