samsonasik / force-https-module
Laminas Mvc 和 Mezzio 应用的强制 HTTPS 模块
Requires
- php: ^7.4|^8.0
- webmozart/assert: ^1.9
Requires (Dev)
- kahlan/kahlan: ^5.2
- laminas/laminas-coding-standard: ^2.0
- laminas/laminas-mvc: ^3.0
- mezzio/mezzio: ^3.0
- php-coveralls/php-coveralls: ^2.1
- phpstan/phpstan: ^1.1
- phpstan/phpstan-webmozart-assert: ^1.0
- rector/rector: 0.12.7
Conflicts
- laminas/laminas-mvc: <3.0
- mezzio/mezzio: <3.0
This package is auto-updated.
Last update: 2024-09-14 06:04:25 UTC
README
介绍
ForceHttpsModule 是一个可配置的模块,用于在您的 Laminas Mvc 和 Mezzio 应用程序中强制使用 HTTPS。
这是版本 ^4.1 的 README 文件,仅支持 Laminas Mvc 版本 3 和 Mezzio 版本 3,以及 php ^7.4|~8.0。
对于 ~4.0.0,您可以在 版本 4.0.x README 中阅读,它仅支持 Laminas Mvc 版本 3 和 Mezzio 版本 3,以及 php ^7.3|~8.0。
对于版本 ^3.0,您可以在 版本 3 README 中阅读,它仅支持 Laminas Mvc 版本 3 和 Mezzio 版本 3,以及 php ^7.1。
对于版本 ^2.0,您可以在 版本 2 README 中阅读,它仅支持 ZF3 和 ZF Expressive 版本 3,以及 php ^7.1。
对于版本 1,您可以在 版本 1 README 中阅读,它仍然支持 ZF2 和 ZF Expressive 版本 1 和 2,以及 php ^5.6|^7.0 支持。
功能
- 启用/禁用强制 HTTPS。
- 强制所有路由使用 HTTPS。
- 强制所有路由使用 HTTPS(除排除列表外)。
- 仅强制特定路由使用 HTTPS。
- 保留头部、请求方法和请求体。
- 启用/禁用 HTTP Strict Transport Security 头部并设置其值。
- 允许在从 http 或已经使用 https 的重定向中添加
www.
前缀。 - 允许在从 http 或已经使用 https 的重定向中移除
www.
前缀。 - 强制 404 页面使用 HTTPS。
安装
1. 需要此模块使用 composer。
composer require samsonasik/force-https-module
2. 复制配置
a. 对于 Laminas Mvc 应用程序,将 force-https-module.local.php.dist
配置文件复制到您的本地 autoload 目录并配置它
或运行复制命令
cp vendor/samsonasik/force-https-module/config/force-https-module.local.php.dist config/autoload/force-https-module.local.php
b. 对于 Mezzio 应用程序,将 mezzio-force-https-module.local.php.dist
配置文件复制到您的本地 autoload 目录并配置它
或运行复制命令
cp vendor/samsonasik/force-https-module/config/mezzio-force-https-module.local.php.dist config/autoload/mezzio-force-https-module.local.php
完成配置后,您可以根据需要进行修改本地配置
<?php // config/autoload/force-https-module.local.php or config/autoload/mezzio-force-https-module.local.php return [ 'force-https-module' => [ 'enable' => true, 'force_all_routes' => true, 'force_specific_routes' => [ // only works if previous's config 'force_all_routes' => false 'checkout', 'payment' ], 'exclude_specific_routes' => [ // a lists of specific routes to not be https // only works if previous config 'force_all_routes' => true 'non-https-route', ], // set HTTP Strict Transport Security Header 'strict_transport_security' => [ // set to false to disable it 'enable' => true, 'value' => 'max-age=31536000', ], // set to true to add "www." prefix during redirection from http or already https 'add_www_prefix' => false, // remove existing "www." prefix during redirection from http or already https // only works if previous's config 'add_www_prefix' => false 'remove_www_prefix' => false, // Force Https for 404 pages 'allow_404' => true, ], // ... ];
3. 最后,启用它
a. 对于 Laminas Mvc 应用程序
// config/modules.config.php or config/application.config.php return [ 'Application' 'ForceHttpsModule', // register here ],
b. 对于 Mezzio 应用程序
对于 mezzio-skeleton ^3.0,您需要打开 config/pipeline.php
文件并添加
$app->pipe(ForceHttpsModule\Middleware\ForceHttps::class);
到最前面的管道记录中。
贡献
欢迎贡献。请阅读 CONTRIBUTING.md