[
  {
    "path": ".editorconfig",
    "content": "; This file is for unifying the coding style for different editors and IDEs.\n; More information at http://editorconfig.org\n\nroot = true\n\n[*]\ncharset = utf-8\nindent_size = 4\nindent_style = space\nend_of_line = lf\ninsert_final_newline = true\ntrim_trailing_whitespace = true\n\n[*.md]\ntrim_trailing_whitespace = false\n"
  },
  {
    "path": ".gitattributes",
    "content": "# Path-based git attributes\n# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html\n\n# Ignore all test and documentation with \"export-ignore\".\n/.gitattributes     export-ignore\n/.gitignore         export-ignore\n/.travis.yml        export-ignore\n/phpunit.xml.dist   export-ignore\n/.scrutinizer.yml   export-ignore\n/tests              export-ignore\n"
  },
  {
    "path": ".github/FUNDING.yml",
    "content": "custom: https://spatie.be/open-source/support-us\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/config.yml",
    "content": "blank_issues_enabled: true\ncontact_links:\n    - name: Feature Request\n      url: https://github.com/spatie/laravel-missing-page-redirector/discussions/new?category=ideas\n      about: Share ideas for new features\n    - name: Ask a Question\n      url: https://github.com/spatie/laravel-missing-page-redirector/discussions/new?category=q-a\n      about: Ask the community for help\n"
  },
  {
    "path": ".github/workflows/php-cs-fixer.yml",
    "content": "name: Check & fix styling\n\non: [push]\n\njobs:\n    php-cs-fixer:\n        runs-on: ubuntu-latest\n\n        steps:\n            - name: Checkout code\n              uses: actions/checkout@v2\n              with:\n                  ref: ${{ github.head_ref }}\n\n            - name: Run PHP CS Fixer\n              uses: docker://oskarstark/php-cs-fixer-ga\n              with:\n                  args: --config=.php-cs-fixer.dist.php --allow-risky=yes\n\n            - name: Commit changes\n              uses: stefanzweifel/git-auto-commit-action@v4\n              with:\n                  commit_message: Fix styling\n"
  },
  {
    "path": ".github/workflows/run-tests.yml",
    "content": "name: run-tests\n\non:\n  - push\n  - pull_request\n\njobs:\n  test:\n    runs-on: ${{ matrix.os }}\n\n    strategy:\n      fail-fast: true\n      matrix:\n        os: [ubuntu-latest]\n        php: [8.4, 8.3, 8.2, 8.1, 8.0]\n        laravel: ['8.*', '9.*', '10.*', '11.*', '12.*', '13.*']\n        dependency-version: [prefer-stable]\n        include:\n          - laravel: 10.*\n            testbench: 8.*\n          - laravel: 9.*\n            testbench: 7.*\n          - laravel: 8.*\n            testbench: 6.*\n          - laravel: 11.*\n            testbench: 9.*\n          - laravel: 12.*\n            testbench: 10.*\n          - laravel: 13.*\n            testbench: 11.*\n        exclude:\n          - laravel: 10.*\n            php: 8.0\n          - laravel: 5.8.*\n            php: 8.0\n          - laravel: 5.8.*\n            php: 8.1\n          - laravel: 6.*\n            php: 8.1\n          - laravel: 7.*\n            php: 8.1\n          - laravel: 9.*\n            php: 7.4\n          - laravel: 11.*\n            php: 8.1\n          - laravel: 11.*\n            php: 8.0\n          - laravel: 12.*\n            php: 8.1\n          - laravel: 12.*\n            php: 8.0\n          - laravel: 13.*\n            php: 8.2\n          - laravel: 13.*\n            php: 8.1\n          - laravel: 13.*\n            php: 8.0\n\n    name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}\n\n    steps:\n      - name: Checkout code\n        uses: actions/checkout@v2\n\n      - name: Setup PHP\n        uses: shivammathur/setup-php@v2\n        with:\n          php-version: ${{ matrix.php }}\n          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo\n          coverage: none\n\n      - name: Install dependencies\n        run: |\n          composer require \"laravel/framework:${{ matrix.laravel }}\" \"orchestra/testbench:${{ matrix.testbench }}\" --no-interaction --no-update\n          composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction\n\n      - name: Execute tests\n        run: vendor/bin/pest\n"
  },
  {
    "path": ".github/workflows/update-changelog.yml",
    "content": "name: \"Update Changelog\"\n\non:\n    release:\n        types: [released]\n\njobs:\n    update:\n        runs-on: ubuntu-latest\n\n        steps:\n            - name: Checkout code\n              uses: actions/checkout@v2\n              with:\n                  ref: main\n\n            - name: Update Changelog\n              uses: stefanzweifel/changelog-updater-action@v1\n              with:\n                  latest-version: ${{ github.event.release.name }}\n                  release-notes: ${{ github.event.release.body }}\n\n            - name: Commit updated CHANGELOG\n              uses: stefanzweifel/git-auto-commit-action@v4\n              with:\n                  branch: main\n                  commit_message: Update CHANGELOG\n                  file_pattern: CHANGELOG.md\n"
  },
  {
    "path": ".gitignore",
    "content": "build\ncomposer.lock\ndocs\nvendor\n.php_cs.cache\n.php-cs-fixer.cache\n"
  },
  {
    "path": ".php-cs-fixer.dist.php",
    "content": "<?php\n\n$finder = Symfony\\Component\\Finder\\Finder::create()\n    ->in([\n        __DIR__ . '/src',\n        __DIR__ . '/tests',\n    ])\n    ->name('*.php')\n    ->ignoreDotFiles(true)\n    ->ignoreVCS(true);\n\nreturn (new PhpCsFixer\\Config())\n    ->setRules([\n        '@PSR12' => true,\n        'array_syntax' => ['syntax' => 'short'],\n        'ordered_imports' => ['sort_algorithm' => 'alpha'],\n        'no_unused_imports' => true,\n        'not_operator_with_successor_space' => true,\n        'trailing_comma_in_multiline' => true,\n        'phpdoc_scalar' => true,\n        'unary_operator_spaces' => true,\n        'binary_operator_spaces' => true,\n        'blank_line_before_statement' => [\n            'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],\n        ],\n        'phpdoc_single_line_var_spacing' => true,\n        'phpdoc_var_without_name' => true,\n        'class_attributes_separation' => [\n            'elements' => [\n                'method' => 'one',\n            ],\n        ],\n        'method_argument_space' => [\n            'on_multiline' => 'ensure_fully_multiline',\n            'keep_multiple_spaces_after_comma' => true,\n        ],\n        'single_trait_insert_per_statement' => true,\n    ])\n    ->setFinder($finder);\n"
  },
  {
    "path": ".phpunit.cache/test-results",
    "content": "{\"version\":\"pest_2.36.0\",\"defects\":[],\"times\":{\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_will_not_interfere_with_existing_pages\":0.037,\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_will_redirect_a_non_existing_page_with_a_permanent_redirect\":0.017,\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_will_redirect_wildcard_routes\":0.001,\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_will_not_redirect_an_url_that_is_not_configured\":0.001,\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_can_use_named_properties\":0.001,\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_can_use_multiple_named_parameters_in_one_segment\":0.001,\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_can_optionally_set_the_redirect_status_code\":0.001,\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_can_use_optional_parameters#('\\/old-segment', '\\/new-segment')\":0.001,\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_can_use_optional_parameters#('\\/old-segment\\/old-segment2', '\\/new-segment\\/old-segment2')\":0.001,\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_can_use_optional_parameters#('\\/old-segment\\/old-segment2\\/old-segment3', '\\/new-segment\\/old-segment2\\/old-segment3')\":0.001,\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_by_default_it_will_not_redirect_requests_that_are_not_404s\":0.001,\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_will_fire_an_event_when_a_route_is_hit\":0.002,\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_will_redirect_depending_on_redirect_status_code_defined\":0.001,\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_will_not_redirect_if_the_status_code_is_not_specified_in_the_config_file\":0.001,\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_will_redirect_on_any_status_code\":0.049,\"P\\\\Tests\\\\RedirectsMissingPagesTest::__pest_evaluable_it_will_fire_an_event_when_no_redirect_was_found\":0.001}}"
  },
  {
    "path": ".phpunit.result.cache",
    "content": "{\"version\":1,\"defects\":{\"\\/Users\\/alexandrumanase\\/Documents\\/repos\\/laravel-missing-page-redirector\\/tests\\/RedirectsMissingPagesTest.php::it\":4},\"times\":{\"\\/Users\\/alexandrumanase\\/Documents\\/repos\\/laravel-missing-page-redirector\\/tests\\/RedirectsMissingPagesTest.php::it\":0.002,\"\\/Users\\/alexandrumanase\\/Documents\\/repos\\/laravel-missing-page-redirector\\/tests\\/RedirectsMissingPagesTest.php::by\":0.002}}"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Changelog\n\nAll notable changes to `laravel-missing-page-redirector` will be documented in this file\n\n## 2.12.0 - 2026-02-21\n\nAdd Laravel 13 support\n\n## 2.11.1 - 2025-02-21\n\n### What's Changed\n\n* Laravel 12.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-missing-page-redirector/pull/88\n\n**Full Changelog**: https://github.com/spatie/laravel-missing-page-redirector/compare/2.11.0...2.11.1\n\n## 2.11.0 - 2025-01-06\n\n### What's Changed\n\n* Update README.md by @hofmannsven in https://github.com/spatie/laravel-missing-page-redirector/pull/86\n* Update README.md by @chengkangzai in https://github.com/spatie/laravel-missing-page-redirector/pull/85\n* fix php8.4 nullable is deprecated by @it-can in https://github.com/spatie/laravel-missing-page-redirector/pull/87\n\n### New Contributors\n\n* @hofmannsven made their first contribution in https://github.com/spatie/laravel-missing-page-redirector/pull/86\n* @chengkangzai made their first contribution in https://github.com/spatie/laravel-missing-page-redirector/pull/85\n* @it-can made their first contribution in https://github.com/spatie/laravel-missing-page-redirector/pull/87\n\n**Full Changelog**: https://github.com/spatie/laravel-missing-page-redirector/compare/2.10.0...2.11.0\n\n## 2.10.0 - 2024-03-12\n\n### What's Changed\n\n* Laravel 11.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-missing-page-redirector/pull/84\n\n**Full Changelog**: https://github.com/spatie/laravel-missing-page-redirector/compare/2.9.4...2.10.0\n\n## 2.9.4 - 2023-01-24\n\n### What's Changed\n\n- Refactor tests to Pest by @alexmanase in https://github.com/spatie/laravel-missing-page-redirector/pull/79\n- Add PHP 8.2 Support by @patinthehat in https://github.com/spatie/laravel-missing-page-redirector/pull/80\n- Laravel 10.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-missing-page-redirector/pull/81\n\n### New Contributors\n\n- @alexmanase made their first contribution in https://github.com/spatie/laravel-missing-page-redirector/pull/79\n- @patinthehat made their first contribution in https://github.com/spatie/laravel-missing-page-redirector/pull/80\n\n**Full Changelog**: https://github.com/spatie/laravel-missing-page-redirector/compare/2.9.3...2.9.4\n\n## 2.9.3 - 2022-10-13\n\n### What's Changed\n\n- Use Laravel container on private Router - closes #77 by @rodrigopedra in https://github.com/spatie/laravel-missing-page-redirector/pull/78\n\n### New Contributors\n\n- @rodrigopedra made their first contribution in https://github.com/spatie/laravel-missing-page-redirector/pull/78\n\n**Full Changelog**: https://github.com/spatie/laravel-missing-page-redirector/compare/2.9.2...2.9.3\n\n## 2.9.2 - 2022-05-13\n\n## What's Changed\n\n- remove Str::of for Laravel 6 compatibility by @chrisGeonet in https://github.com/spatie/laravel-missing-page-redirector/pull/76\n\n## New Contributors\n\n- @chrisGeonet made their first contribution in https://github.com/spatie/laravel-missing-page-redirector/pull/76\n\n**Full Changelog**: https://github.com/spatie/laravel-missing-page-redirector/compare/2.9.1...2.9.2\n\n## 2.9.1 - 2022-04-21\n\n- use `Str` class instead of `str` helper function\n\n**Full Changelog**: https://github.com/spatie/laravel-missing-page-redirector/compare/2.9.0...2.9.1\n\n## 2.9.0 - 2022-04-21\n\n- Add support for wildcard route parameters that span multiple route segments (`/old/*` -> `/new/{wildcard}`)\n\n**Full Changelog**: https://github.com/spatie/laravel-missing-page-redirector/compare/2.8.0...2.9.0\n\n## 2.7.2 - 2021-04-06\n\n- prep for Octane\n\n## 2.7.1 - 2020-12-04\n\n- add support for PHP 8\n\n## 2.7.0 - 2020-09-09\n\n- add support for Laravel 8\n\n## 2.6.0 - 2020-03-03\n\n- add support for Laravel 7\n\n## 2.5.0 - 2019-09-04\n\n- add support for Laravel 6\n\n## 2.4.0 - 2019-02-27\n\n- drop support for PHP 7.1 and below\n- drop support for Laravel 5.7 and below\n\n## 2.3.4 - 2019-02-27\n\n- add support for Laravel 5.8\n\n## 2.3.3 - 2018-12-29\n\n- fix for PHP 7.3\n\n## 2.3.2 - 2018-08-27\n\n- Added: Laravel 5.7 compatibility\n\n## 2.3.1 - 2018-08-14\n\n- Fixed: Optional parameters not working as expected (#44)\n\n## 2.3.0 - 2018-05-02\n\n- Added: an event will get fired when a route was not found\n\n## 2.2.0 - 2018-02-08\n\n- Added: Laravel 5.6 compatibility\n\n## 2.1.1 - 2017-10-19\n\n- Added: Response code to `RouteWasHit` event\n\n## 2.1.0 - 2017-09-09\n\n- Added: Allow redirects to be enable on a status code basis\n\n## 2.0.0 - 2017-08-31\n\n- Added: Laravel 5.5 compatibility\n- Removed: Dropped support for older Laravel versions\n- Changed: Renamed config file from `laravel-missing-page-redirector` to `missing-page-redirector`\n- Refactored tests\n\n## 1.3.0 - 2017-06-11\n\n- Added: `RouteWasHit` event\n\n## 1.2.0 - 2017-01-23\n\n- Added: Laravel 5.4 compatibility\n- Removed: Dropped support for older Laravel versions\n\n## 1.1.0 - 2016-10-27\n\n- Added: Support for determining http status code for a redirect\n\n## 1.0.0 - 2016-10-14\n\n- Initial release\n"
  },
  {
    "path": "LICENSE.md",
    "content": "The MIT License (MIT)\n\nCopyright (c) Spatie bvba <info@spatie.be>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# Redirect missing pages in your Laravel application\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-missing-page-redirector.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-missing-page-redirector)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![run-tests](https://github.com/spatie/laravel-missing-page-redirector/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-missing-page-redirector/actions/workflows/run-tests.yml)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-missing-page-redirector.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-missing-page-redirector)\n\nWhen 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](https://support.google.com/webmasters/answer/93633?hl=en). This package makes that process very easy.\n\nWhen installed you only need to [add your redirects to the config file](https://github.com/spatie/laravel-missing-page-redirector#usage). Want to use the database as your source of redirects? [No problem](https://github.com/spatie/laravel-missing-page-redirector#creating-your-own-redirector)!\n\n## Support us\n\n[<img src=\"https://github-ads.s3.eu-central-1.amazonaws.com/laravel-missing-page-redirector.jpg?t=1\" width=\"419px\" />](https://spatie.be/github-ad-click/laravel-missing-page-redirector)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe 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](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n``` bash\ncomposer require spatie/laravel-missing-page-redirector\n```\n\nThe package will automatically register itself.\n\nNext, prepend/append the `Spatie\\MissingPageRedirector\\RedirectsMissingPages` middleware to your global middleware stack:\n\n```php\n// bootstrap/app.php\n->withMiddleware(function (Middleware $middleware) {\n    $middleware->append([\n        \\Spatie\\MissingPageRedirector\\RedirectsMissingPages::class,\n    ]);\n})\n```\n\n\n\nFinally you must publish the config file:\n\n```php\nphp artisan vendor:publish --provider=\"Spatie\\MissingPageRedirector\\MissingPageRedirectorServiceProvider\"\n```\n\nThis is the contents of the published config file:\n\n```php\nreturn [\n    /*\n     * This is the class responsible for providing the URLs which must be redirected.\n     * The only requirement for the redirector is that it needs to implement the\n     * `Spatie\\MissingPageRedirector\\Redirector\\Redirector`-interface\n     */\n    'redirector' => \\Spatie\\MissingPageRedirector\\Redirector\\ConfigurationRedirector::class,\n    \n    /*\n     * By default the package will only redirect 404s. If you want to redirect on other\n     * response codes, just add them to the array. Leave the array empty to redirect\n     * always no matter what the response code.\n     */\n    'redirect_status_codes' => [\n        \\Symfony\\Component\\HttpFoundation\\Response::HTTP_NOT_FOUND\n    ],\n    \n    /*\n     * When using the `ConfigurationRedirector` you can specify the redirects in this array.\n     * You can use Laravel's route parameters here.\n     */\n    'redirects' => [\n//        '/non-existing-page' => '/existing-page',\n//        '/old-blog/{url}' => '/new-blog/{url}',\n    ],\n\n];\n```\n\n## Usage\n\nCreating a redirect is easy. You just have to add an entry to the `redirects` key in the config file.\n\n```php\n'redirects' => [\n   '/non-existing-page' => '/existing-page',\n],\n```\n\nYou may use route parameters like you're used to when using Laravel's routes:\n\n```php\n    'redirects' => [\n       '/old-blog/{url}' => '/new-blog/{url}',\n    ],\n```\n\nOptional parameters are also... an option:\n\n```php\n    'redirects' => [\n       '/old-blog/{url?}' => '/new-blog/{url}',\n    ],\n```\n\nFinally, you can use an asterix (`*`) as a wildcard parameter that will match multiple URL segments (see [encoded URL slashes in the Laravel docs](https://laravel.com/docs/master/routing#parameters-encoded-forward-slashes) for more info). This is useful when you want to redirect a URL like `/old-blog/foo/bar/baz` to `/new-blog/foo/bar/baz`.\n\n```php\n    'redirects' => [\n       '/old-blog/*' => '/new-blog/{wildcard}', // {wilcard} will be the entire path\n    ],\n```\n\nBy default the package only redirects if the request has a `404` response code but it's possible to be redirected on any response code.\nTo achieve this you may change the ```redirect_status_codes``` option to an array of response codes or leave it empty if you wish to be redirected no matter what the response code was sent to the URL.\nYou may override this using the following syntax to achieve this:  \n\n```php\n    'redirect_status_codes' => [\\Symfony\\Component\\HttpFoundation\\Response::HTTP_NOT_FOUND],\n```\n\nIt is also possible to optionally specify which http response code is used when performing the redirect. By default the ```301 Moved Permanently``` response code is set. You may override this using the following syntax:   \n\n```php\n    'redirects' => [\n       'old-page' => ['/new-page', 302],\n    ],\n```\n\n## Events\n\nThe package will fire a `RouteWasHit` event when it found a redirect for the route. A `RedirectNotFound` is fired when no redirect was found.\n\n## Creating your own redirector\n\nBy default this package will use the `Spatie\\MissingPageRedirector\\Redirector\\ConfigurationRedirector` which will get its redirects from the config file. If you want to use another source for your redirects (for example a database) you can create your own redirector.\n\nA valid redirector is any class that implements the `Spatie\\MissingPageRedirector\\Redirector\\Redirector`-interface. That interface looks like this:\n\n```php\nnamespace Spatie\\MissingPageRedirector\\Redirector;\n\nuse Symfony\\Component\\HttpFoundation\\Request;\n\ninterface Redirector\n{\n    public function getRedirectsFor(Request $request): array;\n}\n\n```\n\nThe `getRedirectsFor` method should return an array in which the keys are the old URLs and the values the new URLs.\n\n## If you want to use `Route::fallback`\n\nIf you do not wish to overwrite the default redirector, or if you already have existing `Route::fallback` logic based on [laravel docs](https://laravel.com/docs/11.x/routing#fallback-routes), you can use this package as follow.\nIn the bottom of your `web.php` file,\n\n```php\nuse Spatie\\MissingPageRedirector\\MissingPageRouter;\n//... Your other route\n\nRoute::fallback(function (Request $request) {\n    $redirectResponse = app(MissingPageRouter::class)->getRedirectFor($request);\n\n    if ($redirectResponse !== null) {\n        return $redirectResponse;\n    }\n    //... Your other logic\n});\n```\nYou can adjust the priority of redirect base on your needs.\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n"
  },
  {
    "path": "composer.json",
    "content": "{\n    \"name\": \"spatie/laravel-missing-page-redirector\",\n    \"description\": \"Redirect missing pages in your Laravel application\",\n    \"keywords\": [\n        \"spatie\",\n        \"laravel-missing-page-redirector\"\n    ],\n    \"homepage\": \"https://github.com/spatie/laravel-missing-page-redirector\",\n    \"license\": \"MIT\",\n    \"authors\": [\n        {\n            \"name\": \"Freek Van der Herten\",\n            \"email\": \"freek@spatie.be\",\n            \"homepage\": \"https://spatie.be\",\n            \"role\": \"Developer\"\n        }\n    ],\n    \"require\": {\n        \"php\": \"^8.0|^8.1\",\n        \"laravel/framework\": \"^8.28|^9.0|^10.0|^11.0|^12.0|^13.0\",\n        \"spatie/url\": \"^1.0|^2.0\"\n    },\n    \"require-dev\": {\n        \"orchestra/testbench\": \"^6.0|^7.0|^8.0|^9.0|^10.0|^11.0\",\n        \"pestphp/pest\": \"^1.22|^2.34|^3.7|^4.0\",\n        \"phpunit/phpunit\": \"^9.0|^9.3|^10.5|^11.5.3|^12.5.12\"\n    },\n    \"autoload\": {\n        \"psr-4\": {\n            \"Spatie\\\\MissingPageRedirector\\\\\": \"src\"\n        }\n    },\n    \"autoload-dev\": {\n        \"psr-4\": {\n            \"Spatie\\\\MissingPageRedirector\\\\Test\\\\\": \"tests\"\n        }\n    },\n    \"scripts\": {\n        \"test\": \"vendor/bin/pest\"\n    },\n    \"config\": {\n        \"sort-packages\": true,\n        \"allow-plugins\": {\n            \"pestphp/pest-plugin\": true\n        }\n    },\n    \"extra\": {\n        \"laravel\": {\n            \"providers\": [\n                \"Spatie\\\\MissingPageRedirector\\\\MissingPageRedirectorServiceProvider\"\n            ]\n        }\n    },\n    \"minimum-stability\": \"dev\",\n    \"prefer-stable\": true\n}\n"
  },
  {
    "path": "config/missing-page-redirector.php",
    "content": "<?php\n\nreturn [\n    /*\n     * This is the class responsible for providing the URLs which must be redirected.\n     * The only requirement for the redirector is that it needs to implement the\n     * `Spatie\\MissingPageRedirector\\Redirector\\Redirector`-interface\n     */\n    'redirector' => \\Spatie\\MissingPageRedirector\\Redirector\\ConfigurationRedirector::class,\n\n    /*\n     * By default the package will only redirect 404s. If you want to redirect on other\n     * response codes, just add them to the array. Leave the array empty to redirect\n     * always no matter what the response code.\n     */\n    'redirect_status_codes' => [\n        \\Symfony\\Component\\HttpFoundation\\Response::HTTP_NOT_FOUND,\n    ],\n\n    /*\n     * When using the `ConfigurationRedirector` you can specify the redirects in this array.\n     * You can use Laravel's route parameters here.\n     */\n    'redirects' => [\n        //        '/non-existing-page' => '/existing-page',\n        //        '/old-blog/{url}' => '/new-blog/{url}',\n    ],\n\n];\n"
  },
  {
    "path": "phpunit.xml.dist",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" bootstrap=\"vendor/autoload.php\" backupGlobals=\"false\" colors=\"true\" processIsolation=\"false\" stopOnFailure=\"false\" xsi:noNamespaceSchemaLocation=\"https://schema.phpunit.de/10.5/phpunit.xsd\" cacheDirectory=\".phpunit.cache\" backupStaticProperties=\"false\">\n  <testsuites>\n    <testsuite name=\"Spatie Test Suite\">\n      <directory>tests</directory>\n    </testsuite>\n  </testsuites>\n  <source>\n    <include>\n      <directory suffix=\".php\">src/</directory>\n    </include>\n  </source>\n</phpunit>\n"
  },
  {
    "path": "src/Events/RedirectNotFound.php",
    "content": "<?php\n\nnamespace Spatie\\MissingPageRedirector\\Events;\n\nuse Symfony\\Component\\HttpFoundation\\Request;\n\nclass RedirectNotFound\n{\n    /** @var Request */\n    public $request;\n\n    public function __construct(Request $request)\n    {\n        $this->request = $request;\n    }\n}\n"
  },
  {
    "path": "src/Events/RouteWasHit.php",
    "content": "<?php\n\nnamespace Spatie\\MissingPageRedirector\\Events;\n\nclass RouteWasHit\n{\n    /** @var string */\n    public $route;\n\n    /** @var string */\n    public $missingUrl;\n\n    /** @var int|null */\n    public $statusCode;\n\n    public function __construct(string $route, string $missingUrl, ?int $statusCode = null)\n    {\n        $this->route = $route;\n\n        $this->missingUrl = $missingUrl;\n\n        $this->statusCode = $statusCode;\n    }\n}\n"
  },
  {
    "path": "src/MissingPageRedirectorServiceProvider.php",
    "content": "<?php\n\nnamespace Spatie\\MissingPageRedirector;\n\nuse Illuminate\\Routing\\Router;\nuse Illuminate\\Support\\ServiceProvider;\nuse Spatie\\MissingPageRedirector\\Redirector\\Redirector;\n\nclass MissingPageRedirectorServiceProvider extends ServiceProvider\n{\n    public function boot()\n    {\n        $this->publishes([\n            __DIR__.'/../config/missing-page-redirector.php' => config_path('missing-page-redirector.php'),\n        ], 'config');\n\n        $this->app->bind(Redirector::class, config('missing-page-redirector.redirector'));\n\n        $this->app->bind(MissingPageRouter::class, function ($app) {\n            $router = new Router($app['events'], $app);\n\n            $redirector = $app->make(Redirector::class);\n\n            return new MissingPageRouter($router, $redirector);\n        });\n    }\n\n    public function register()\n    {\n        $this->mergeConfigFrom(__DIR__.'/../config/missing-page-redirector.php', 'missing-page-redirector');\n    }\n}\n"
  },
  {
    "path": "src/MissingPageRouter.php",
    "content": "<?php\n\nnamespace Spatie\\MissingPageRedirector;\n\nuse Exception;\nuse Illuminate\\Routing\\Router;\nuse Illuminate\\Support\\Str;\nuse Spatie\\MissingPageRedirector\\Events\\RedirectNotFound;\nuse Spatie\\MissingPageRedirector\\Events\\RouteWasHit;\nuse Spatie\\MissingPageRedirector\\Redirector\\Redirector;\nuse Symfony\\Component\\HttpFoundation\\Request;\nuse Symfony\\Component\\HttpFoundation\\Response;\n\nclass MissingPageRouter\n{\n    /** @var \\Illuminate\\Routing\\Router */\n    protected $router;\n\n    /** @var \\Spatie\\MissingPageRedirector\\Redirector\\Redirector */\n    protected $redirector;\n\n    public function __construct(Router $router, Redirector $redirector)\n    {\n        $this->router = $router;\n        $this->redirector = $redirector;\n    }\n\n    /**\n     * @param \\Symfony\\Component\\HttpFoundation\\Request $request\n     *\n     * @return \\Illuminate\\Http\\Response|null\n     */\n    public function getRedirectFor(Request $request)\n    {\n        $redirects = $this->redirector->getRedirectsFor($request);\n\n        collect($redirects)->each(function ($redirects, $missingUrl) {\n            if (Str::contains($missingUrl, '*')) {\n                $missingUrl = str_replace('*', '{wildcard}', $missingUrl);\n            }\n\n            $this->router->get($missingUrl, function () use ($redirects, $missingUrl) {\n                $redirectUrl = $this->determineRedirectUrl($redirects);\n                $statusCode = $this->determineRedirectStatusCode($redirects);\n\n                event(new RouteWasHit($redirectUrl, $missingUrl, $statusCode));\n\n                return redirect()->to(\n                    $redirectUrl,\n                    $statusCode\n                );\n            })->where('wildcard', '.*');\n        });\n\n        try {\n            return $this->router->dispatch($request);\n        } catch (Exception $e) {\n            event(new RedirectNotFound($request));\n\n            return;\n        }\n    }\n\n    protected function determineRedirectUrl($redirects): string\n    {\n        if (is_array($redirects)) {\n            return $this->resolveRouterParameters($redirects[0]);\n        }\n\n        return $this->resolveRouterParameters($redirects);\n    }\n\n    protected function determineRedirectStatusCode($redirects): int\n    {\n        return is_array($redirects) ? $redirects[1] : Response::HTTP_MOVED_PERMANENTLY;\n    }\n\n    protected function resolveRouterParameters(string $redirectUrl): string\n    {\n        foreach ($this->router->getCurrentRoute()->parameters() as $key => $value) {\n            $redirectUrl = str_replace(\"{{$key}}\", $value, $redirectUrl);\n        }\n\n        $redirectUrl = preg_replace('/\\/{[\\w-]+}/', '', $redirectUrl);\n\n        return $redirectUrl;\n    }\n}\n"
  },
  {
    "path": "src/Redirector/ConfigurationRedirector.php",
    "content": "<?php\n\nnamespace Spatie\\MissingPageRedirector\\Redirector;\n\nuse Symfony\\Component\\HttpFoundation\\Request;\n\nclass ConfigurationRedirector implements Redirector\n{\n    public function getRedirectsFor(Request $request): array\n    {\n        return config('missing-page-redirector.redirects');\n    }\n}\n"
  },
  {
    "path": "src/Redirector/Redirector.php",
    "content": "<?php\n\nnamespace Spatie\\MissingPageRedirector\\Redirector;\n\nuse Symfony\\Component\\HttpFoundation\\Request;\n\ninterface Redirector\n{\n    public function getRedirectsFor(Request $request): array;\n}\n"
  },
  {
    "path": "src/RedirectsMissingPages.php",
    "content": "<?php\n\nnamespace Spatie\\MissingPageRedirector;\n\nuse Closure;\nuse Illuminate\\Http\\Request;\n\nclass RedirectsMissingPages\n{\n    public function handle(Request $request, Closure $next)\n    {\n        $response = $next($request);\n\n        if (! $this->shouldRedirect($response)) {\n            return $response;\n        }\n\n        $redirectResponse = app(MissingPageRouter::class)->getRedirectFor($request);\n\n        return $redirectResponse ?? $response;\n    }\n\n    protected function shouldRedirect($response): bool\n    {\n        $redirectStatusCodes = config('missing-page-redirector.redirect_status_codes');\n\n        if (is_null($redirectStatusCodes)) {\n            return false;\n        }\n\n        if (! count($redirectStatusCodes)) {\n            return true;\n        }\n\n        return in_array($response->getStatusCode(), $redirectStatusCodes);\n    }\n}\n"
  },
  {
    "path": "tests/Pest.php",
    "content": "<?php\n\nuses(Spatie\\MissingPageRedirector\\Test\\TestCase::class)->in('.');\n"
  },
  {
    "path": "tests/RedirectsMissingPagesTest.php",
    "content": "<?php\n\nuse Illuminate\\Support\\Facades\\Event;\nuse Spatie\\MissingPageRedirector\\Events\\RedirectNotFound;\nuse Spatie\\MissingPageRedirector\\Events\\RouteWasHit;\nuse Symfony\\Component\\HttpFoundation\\Response;\n\nit('will not interfere with existing pages', function () {\n    $this->get('existing-page')\n        ->assertSee('existing page');\n});\nit('will redirect a non existing page with a permanent redirect', function () {\n    config()->set('missing-page-redirector.redirects', [\n        '/non-existing-page' => '/existing-page',\n    ]);\n\n    $this->get('non-existing-page')\n        ->assertStatus(Response::HTTP_MOVED_PERMANENTLY)\n        ->assertRedirect('/existing-page');\n});\nit('will redirect wildcard routes', function () {\n    config()->set('missing-page-redirector.redirects', [\n        '/path/*' => '/new-path/{wildcard}',\n    ]);\n\n    $this->get('path/to/a/page')\n        ->assertStatus(Response::HTTP_MOVED_PERMANENTLY)\n        ->assertRedirect('/new-path/to/a/page');\n});\nit('will not redirect an url that is not configured', function () {\n    config()->set('missing-page-redirector.redirects', [\n        '/non-existing-page' => '/existing-page',\n    ]);\n\n    $this->get('/not-configured')\n        ->assertStatus(Response::HTTP_NOT_FOUND);\n});\nit('can use named properties', function () {\n    config()->set('missing-page-redirector.redirects', [\n        '/segment1/{id}/segment2/{slug}' => '/segment2/{slug}',\n    ]);\n\n    $this->get('/segment1/123/segment2/abc')\n        ->assertRedirect('/segment2/abc');\n});\nit('can use multiple named parameters in one segment', function () {\n    config()->set('missing-page-redirector.redirects', [\n        '/new-segment/{id}-{slug}' => '/new-segment/{id}/',\n    ]);\n\n    $this->get('/new-segment/123-blablabla')\n        ->assertRedirect('/new-segment/123');\n});\nit('can optionally set the redirect status code', function () {\n    config()->set('missing-page-redirector.redirects', [\n        '/temporarily-moved' => ['/just-for-now', 302],\n    ]);\n\n    $this->get('/temporarily-moved')\n        ->assertStatus(302)\n        ->assertRedirect('/just-for-now');\n});\nit('can use optional parameters', function (string $getRoute, string $redirectRoute) {\n    config()->set('missing-page-redirector.redirects', [\n        '/old-segment/{parameter1?}/{parameter2?}' => '/new-segment/{parameter1}/{parameter2}',\n    ]);\n\n    $this->get($getRoute)\n        ->assertRedirect($redirectRoute);\n})->with([\n    ['/old-segment', '/new-segment'],\n    ['/old-segment/old-segment2', '/new-segment/old-segment2'],\n    ['/old-segment/old-segment2/old-segment3', '/new-segment/old-segment2/old-segment3'],\n]);\nit('by default it will not redirect requests that are not 404s', function () {\n    $this->get('/response-code/500')\n        ->assertStatus(500);\n});\nit('will fire an event when a route is hit', function () {\n    Event::fake();\n\n    config()->set('missing-page-redirector.redirects', [\n        '/old-segment/{parameter1?}/{parameter2?}' => '/new-segment/',\n    ]);\n\n    $this->get('/old-segment');\n\n    Event::assertDispatched(RouteWasHit::class);\n});\nit('will redirect depending on redirect status code defined', function () {\n    config()->set('missing-page-redirector.redirect_status_codes', [418, 500]);\n\n    config()->set('missing-page-redirector.redirects', [\n        '/response-code/500' => '/existing-page',\n    ]);\n\n    $this->get('/response-code/500')\n        ->assertRedirect('/existing-page');\n});\nit('will not redirect if the status code is not specified in the config file', function () {\n    config()->set('missing-page-redirector.redirect_status_codes', [418, 403]);\n\n    config()->set('missing-page-redirector.redirects', [\n        '/response-code/500' => '/existing-page',\n    ]);\n\n    $this->get('/response-code/500')\n        ->assertStatus(500);\n});\nit('will redirect on any status code', function () {\n    config()->set('missing-page-redirector.redirect_status_codes', []);\n\n    config()->set('missing-page-redirector.redirects', [\n        '/response-code/418' => '/existing-page',\n    ]);\n\n    $this->get('/response-code/418')\n        ->assertRedirect('/existing-page');\n});\nit('will fire an event when no redirect was found', function () {\n    Event::fake();\n\n    $this->get('/response-code/404');\n\n    Event::assertDispatched(RedirectNotFound::class);\n});\n"
  },
  {
    "path": "tests/TestCase.php",
    "content": "<?php\n\nnamespace Spatie\\MissingPageRedirector\\Test;\n\nuse Illuminate\\Contracts\\Http\\Kernel;\nuse Orchestra\\Testbench\\TestCase as Orchestra;\nuse PHPUnit\\Framework\\Assert as PHPUnit;\nuse Route;\nuse Spatie\\MissingPageRedirector\\MissingPageRedirectorServiceProvider;\nuse Spatie\\MissingPageRedirector\\RedirectsMissingPages;\n\nabstract class TestCase extends Orchestra\n{\n    protected function setUp(): void\n    {\n        parent::setUp();\n\n        $this->setUpRoutes($this->app);\n    }\n\n    /**\n     * @param \\Illuminate\\Foundation\\Application $app\n     *\n     * @return array\n     */\n    protected function getPackageProviders($app)\n    {\n        return [\n            MissingPageRedirectorServiceProvider::class,\n        ];\n    }\n\n    /**\n     * @param \\Illuminate\\Foundation\\Application $app\n     */\n    protected function getEnvironmentSetUp($app)\n    {\n        $app['config']->set('app.key', '6rE9Nz59bGRbeMATftriyQjrpF7DcOQm');\n        $app['config']->set('app.debug', true);\n        $app->make(Kernel::class)->pushMiddleware(RedirectsMissingPages::class);\n    }\n\n    /**\n     * @param \\Illuminate\\Foundation\\Application $app\n     */\n    protected function setUpRoutes($app)\n    {\n        Route::get('/existing-page', function () {\n            return 'existing page';\n        });\n\n        Route::get('response-code/{responseCode}', function (int $responseCode) {\n            abort($responseCode);\n        });\n    }\n\n    /**\n     * Assert whether the client was redirected to a given URI.\n     *\n     * @param  string  $uri\n     * @param  array  $with\n     * @return $this\n     */\n    public function assertRedirectedTo($uri, $with = [])\n    {\n        PHPUnit::assertInstanceOf('Illuminate\\Http\\RedirectResponse', $this->response);\n\n        PHPUnit::assertEquals($this->app['url']->to($uri), $this->response->headers->get('Location'));\n\n        return $this;\n    }\n}\n"
  }
]