middlewares / www
Middleware to add or remove the www subdomain in the host uri and returns a redirect response
Requires
- php: ^7.2 || ^8.0
- middlewares/utils: ^3.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- laminas/laminas-diactoros: ^2.3
- oscarotero/php-cs-fixer-config: ^1.0
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^8|^9
- squizlabs/php_codesniffer: ^3.0
README
Middleware to add or remove the www
subdomain in the host uri and returns a redirect response. The following types of hosts wont be changed:
- The one word hosts, for example:
http://localhost
. - The ip based hosts, for example:
http://0.0.0.0
.
Requirements
- PHP >= 7.2
- A PSR-7 http library
- A PSR-15 middleware dispatcher
Installation
This package is installable and autoloadable via Composer as middlewares/www.
composer require middlewares/www
Usage
Set true
to add the www subdomain and false
to remove it.
//Remove www $www = new Middlewares\Www(false); //Add www $www = new Middlewares\Www(true);
Optionally, you can provide a Psr\Http\Message\ResponseFactoryInterface
as the second argument to create the redirect response (301
). If it's not defined, Middleware\Utils\Factory will be used to detect it automatically.
$responseFactory = new MyOwnResponseFactory(); $www = new Middlewares\Www(true, $responseFactory);
Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.
The MIT License (MIT). Please see LICENSE for more information.