This middleware just removes a prefix from the request uri.
This middleware can be installed with composer.
$ composer require los/basepath
Just add the middleware as one of the first in your application.
For example:
$app->pipe(new \LosMiddleware\BasePath\BasePath('/site'));
Every request with /site
prefix will be replaced:
/site => /
/site/blog => /blog
/site/contact-us => /contact-us
If you are using expressive-skeleton, you can copy config/los-basepath.global.php.dist
to config/autoload/los-basepath.global.php
and modify configuration as your needs.
Zend Expressive comes with a UrlHelper that generates a url for your application, but we need to inject the new basePath.
This modules comes with a UrlHelperFactory that does this job for you. Just add the following configuration:
'dependencies' => [
'factories' => [
Zend\Expressive\Helper\UrlHelper::class => LosMiddleware\BasePath\UrlHelperFactory::class,
/* ... */
],
],