PHP code example of vkovic / laravel-db-redirector
1. Go to this page and download the library: Download vkovic/laravel-db-redirector library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
RedirectRule::create([
'origin' => '/one/{param}',
'destination' => '/two/{param}'
]);
// If we visit: "/one/foo" we will end up at "two/foo"
RedirectRule::create([
'origin' => '/one/{param1?}/{param2?}',
'destination' => '/four/{param1}/{param2}'
]);
// If we visit: "/one" we'll end up at "/four
// If we visit: "/one/two" we'll end up at "/four/two"
// If we visit: "/one/two/three" we'll end up at "/four/two/three"
RedirectRule::create([
'origin' => '/one',
'destination' => '/two'
]);
RedirectRule::create([
'origin' => '/two',
'destination' => '/three'
]);
RedirectRule::create([
'origin' => '/three',
'destination' => '/four'
]);
// If we visit: "/one" we'll end up at "/four"
RedirectRule::deleteChainedRecursively('/four');
RedirectRule::create(['origin' => '/one/two', 'destination' => '/three/four']);
RedirectRule::create(['origin' => '/three/four', 'destination' => '/five/six']);
// One more with same destination ("/five/six") as the previous one.
RedirectRule::create(['origin' => '/ten/eleven', 'destination' => '/five/six']);
try {
RedirectRule::deleteChainedRecursively('five/six');
} catch (\Exception $e) {
// ... handle exception
}
RedirectRule::create(['origin' => '/one/{param}/three', 'destination' => '/four']);
RedirectRule::create(['origin' => '/{param}/two/three', 'destination' => '/five']);
// If we visit: "/one/two/three" it corresponds to both of rules above,
// so, where should we end up: "/four" or "/five" ?
// ...
// It does not have anything to do with rule order in our rules table!
bash
php artisan migrate
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.