PHP code example of middlewares / base-path
1. Go to this page and download the library: Download middlewares/base-path 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/ */
middlewares / base-path example snippets
Dispatcher::run([
new Middlewares\BasePath('/base/path')
]);
$response = Dispatcher::run([
(new Middlewares\BasePath('/base/path'))->fixLocation(),
function () {
return Factory::createResponse(301)->withHeader('Location', '/post/1');
}
]);
echo $response->getHeader('Location'); // Returns /base/path/post/1
// Save the original uri with basepath in the custom attribute "before-basepath-uri"
$basepath = (new Middlewares\BasePath())->attribute('pre-basepath-path');