samsonasik / ForceHttpsModule

:link: Configurable module for force https in your ZF2/ZF3 Mvc and ZF Expressive Application.


ForceHttpsModule

Latest Version Build Status Coverage Status PHPStan Downloads

Introduction

ForceHttpsModule is a configurable module for force https in your ZF2/ZF3 Mvc and ZF Expressive Application.

Features

  • [x] Enable/disable force https.
  • [x] Force Https to All routes.
  • [x] Force Https to specific routes only.
  • [x] Keep headers, request method, and request body.
  • [x] Enable/disable HTTP Strict Transport Security Header and set its value.
  • [x] Allow add www. prefix during redirection from http or already https.
  • [x] Allow remove www. prefix during redirection from http or already https.

Installation

1. Require this module uses composer.

composer require samsonasik/force-https-module

2. Copy config

a. For ZF2/ZF3 Mvc application, copy force-https-module.local.php.dist config to your local's autoload and configure it

source destination
vendor/samsonasik/force-https-module/config/force-https-module.local.php.dist config/autoload/force-https-module.local.php

Or run copy command:

cp vendor/samsonasik/force-https-module/config/force-https-module.local.php.dist config/autoload/force-https-module.local.php

b. For ZF Expressive application, copy expressive-force-https-module.local.php.dist config to your local's autoload and configure it

source destination
vendor/samsonasik/force-https-module/config/expressive-force-https-module.local.php.dist config/autoload/expressive-force-https-module.local.php

Or run copy command:

cp vendor/samsonasik/force-https-module/config/expressive-force-https-module.local.php.dist config/autoload/expressive-force-https-module.local.php

When done, you can modify your local config:

<?php
// config/autoload/force-https-module.local.php or config/autoload/expressive-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'
        ],
        // 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,
    ],
    // ...
];

3. Lastly, enable it

a. For ZF Mvc application

// config/modules.config.php or config/application.config.php
return [
    'Application'
    'ForceHttpsModule', // register here
],

b. For ZF Expressive application

For zend-expressive-skeleton ^1.0, It's should already just works!

For zend-expressive-skeleton ^2.0, you need to open config/pipeline.php and add:

$app->pipe(ForceHttpsModule\Middleware\ForceHttps::class);

at the very first pipeline records.

Contributing

Contributions are very welcome. Please read CONTRIBUTING.md

Copyright (c) 2017 Abdul Malik Ikhsan

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
php composer.phar require "samsonasik/force-https-module"

Require

  • php: ^5.6 || ^7.0
  • zendframework/zend-console: ^2.5
  • zendframework/zend-http: ^2.7 || ^3.0

Require Dev

  • kahlan/kahlan: ^3.0
  • satooshi/php-coveralls: ^1.0
  • zendframework/zend-mvc: ^2.5 || ^3.0
  • zendframework/zend-expressive: ^1.0 || ^2.0