|
1 |
| -# Laravel package for manage your URL redirects in database to get better SEO results |
| 1 | +# Laravel package for manage your URL redirects in database or other sources to get better SEO results |
2 | 2 |
|
3 | 3 | [](https://packagist.org/packages/SiroDiaz/laravel-redirection)
|
4 | 4 | [](https://github.com/SiroDiaz/laravel-redirection/actions?query=workflow%3Arun-tests+branch%3Amain)
|
@@ -55,24 +55,89 @@ return [
|
55 | 55 |
|
56 | 56 | /*
|
57 | 57 | |--------------------------------------------------------------------------
|
58 |
| - | Default model used for redirections |
| 58 | + | Default Redirect status code (in case of not defined) |
| 59 | + |-------------------------------------------------------------------------- |
| 60 | + | |
| 61 | + | Status code used by default to redirect from an old URL to a new mapped |
| 62 | + | URL. |
| 63 | + | |
| 64 | + */ |
| 65 | + 'default_status_code' => (int)env('REDIRECT_DEFAULT_STATUS', 301), |
| 66 | + |
| 67 | + /* |
| 68 | + |-------------------------------------------------------------------------- |
| 69 | + | Redirect Driver |
| 70 | + |-------------------------------------------------------------------------- |
| 71 | + | |
| 72 | + | Here you may specify the default redirect driver that you want to use. |
| 73 | + | The "config" driver is used by default when you want to code faster. |
| 74 | + | Consider database driver better for admin panel configuration backed by |
| 75 | + | a relational DB. |
| 76 | + | |
| 77 | + */ |
| 78 | + 'driver' => env('REDIRECT_DRIVER', 'config'), |
| 79 | + |
| 80 | + /* |
| 81 | + |-------------------------------------------------------------------------- |
| 82 | + | Array containing all available drivers and its implementations and source |
59 | 83 | |--------------------------------------------------------------------------
|
60 | 84 | |
|
61 | 85 | | Concrete implementation for the "redirection model".
|
62 |
| - | To extend or replace this functionality, change the value below with your full "redirection model" FQN. |
| 86 | + | To extend or replace this functionality, change the value below with |
| 87 | + | your full "redirection model" FQN. |
63 | 88 | |
|
64 | 89 | | Your class will have to (first option is recommended):
|
65 | 90 | | - extend the "SiroDiaz\Redirection\Models\Redirection" class
|
66 | 91 | | - or at least implement the "SiroDiaz\Redirection\Contracts\RedirectionModelContract" interface.
|
67 | 92 | |
|
68 | 93 | | Regardless of the concrete implementation below, you can still use it like:
|
69 |
| - | - app('redirection.model') OR app('\SiroDiaz\Redirection\Models\Redirection\Contracts\RedirectsModelContract') |
70 |
| - | - or you could even use your own class as a direct implementation |
| 94 | + | - app('redirection.') OR app('\SiroDiaz\Redirection\Contracts\RedirectionModelContract') |
| 95 | + | - or you could even use your own class as a direct implementation. For this |
| 96 | + | case you must extend from "SiroDiaz\Redirection\Models\Redirection" model class and |
| 97 | + | replace in the published config file 'drivers.database.source'. |
| 98 | + | |
71 | 99 | |
|
72 | 100 | */
|
73 |
| - 'model' => SiroDiaz\Redirection\Models\Redirection::class, |
| 101 | + 'drivers' => [ |
| 102 | + 'config' => [ |
| 103 | + 'driver' => SiroDiaz\Redirection\Drivers\FileRedirector::class, |
| 104 | + 'source' => 'redirection.urls', |
| 105 | + ], |
| 106 | + 'database' => [ |
| 107 | + 'driver' => SiroDiaz\Redirection\Drivers\DatabaseRedirector::class, |
| 108 | + 'source' => SiroDiaz\Redirection\Models\Redirection::class, |
| 109 | + ], |
| 110 | + ], |
| 111 | + |
| 112 | + /* |
| 113 | + |-------------------------------------------------------------------------- |
| 114 | + | Url list with redirections used for config driver |
| 115 | + |-------------------------------------------------------------------------- |
| 116 | + | |
| 117 | + | You can use urls array of two different ways. The simple one uses the |
| 118 | + | default redirect status code ('redirection.default_status_code'). |
| 119 | + | Example: |
| 120 | + | 'urls' => [ |
| 121 | + | '/old/url' => '/new/url', |
| 122 | + | '/another/old/url' => '/another/new/url', |
| 123 | + | '/url/with?id=123' => '/url/with/123', |
| 124 | + | ], |
| 125 | + | |
| 126 | + | The second way to write redirect urls in your config/redirection.php |
| 127 | + | is using associative arrays. You can combine this method with the previous one. |
| 128 | + | Look at this example: |
| 129 | + | 'urls' => [ |
| 130 | + | '/old/url' => ['new_url' => '/new/url', 'status_code' => 302], |
| 131 | + | '/another/old/url' => '/another/new/url', |
| 132 | + | '/url/with?id=123' => ['new_url' => '/url/with/123'], |
| 133 | + | ], |
| 134 | + | |
| 135 | + */ |
| 136 | + 'urls' => [], |
| 137 | + |
74 | 138 | ];
|
75 | 139 |
|
| 140 | + |
76 | 141 | ```
|
77 | 142 |
|
78 | 143 | You can change and extend the default `SiroDiaz\Redirection\Models\Redirection` model class.
|
@@ -111,7 +176,10 @@ Ey! **don't forget** to append the middleware `SiroDiaz\Redirection\RedirectRequ
|
111 | 176 | ],
|
112 | 177 | ```
|
113 | 178 |
|
114 |
| -## Testing |
| 179 | +## Extending and creating new redirect Drivers |
| 180 | +**TODO** |
| 181 | + |
| 182 | +## Testing this package for contribution |
115 | 183 |
|
116 | 184 | ```bash
|
117 | 185 | composer test
|
|
0 commit comments