2017 © Pedro Peláez
 

library laravel-force-https

Easy redirect to https for Laravel

image

yaroslawww/laravel-force-https

Easy redirect to https for Laravel

  • Sunday, February 18, 2018
  • by angecode
  • Repository
  • 0 Watchers
  • 7 Stars
  • 1,518 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 7 Versions
  • 29 % Grown

The README.md

Laravel Force Https

Latest Version on Packagist MIT Licensed Total Downloads Build Status Code Coverage Scrutinizer Code Quality, (*1)

An easy redirect to https for Laravel., (*2)

Redirects using server config

The fastest and easiest way to do a redirect is to configure the server to redirect requests itself (an example is shown below). But in some situations you may not have access to the configuration, or you need to do additional checks using PHP. Then this package comes in handy., (*3)

Redirect using apache2

Add to .htaccess, (*4)

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Header always set Content-Security-Policy "upgrade-insecure-requests;"

Redirect using nginx

You need to migrate configurations from port 80 to 443 and then add redirect from port 80 to port 443, (*5)

server {
    listen 443 ssl http2;
    server_name my-domain.example www.my-domain.example;

    # ... configuration
}
server {
    listen 80;
    server_name my-domain.example www.my-domain.example;
    return 301 https://my-domain.example$request_uri;
}

Table of Contents

Compatibility

For use php < 8.0 please use version "^2.0", (*6)

Installation

composer require yaroslawww/laravel-force-https

Usage

Middleware

Moreover, this package includes a middleware object to redirect all "non-ssl" routes to the corresponding "ssl"., (*7)

So, if a user navigates to http://url-to-laravel/test and the system has this middleware active it would redirect (301) him automatically to https://url-to-laravel/test. This is mainly used to avoid duplicate content and improve SEO performance., (*8)

To do so, you have to register the middleware in the app/Http/Kernel.php file like this:, (*9)

    //app/Http/Kernel.php

    /**
     * The application's route middleware.
     *
     * @var array
     */
    protected $routeMiddleware = [
        /**** OTHER MIDDLEWARE ****/
        'https' => \ForceHttps\Middleware\RedirectToHttps::class,
        // REDIRECTION MIDDLEWARE
    ];

    // /routes/web.php

    Route::middleware('https')
        ->group(function() {
            /** ADD ALL SECURE ROUTES INSIDE THIS GROUP **/
            Route::get('/', function()
            {
                //
            });

            Route::get('test',function()
            {
                //
            });
        });

    /** OTHER PAGES THAT SHOULD NOT BE SECURE **/

Config

Config Files

In order to edit the default configuration for this package you may execute:, (*10)

php artisan vendor:publish --provider="ForceHttps\ServiceProvider"

After that, config/force-https.php will be created. Inside this file you will find all the fields that can be edited in this package., (*11)

Since you will typically need to overwrite the assets every time the package is updated, you may use the --force flag:, (*12)


php artisan vendor:publish --provider="ForceHttps\ServiceProvider" --force

Changelog

View changelog here -> changelog, (*13)

License

Credits

  • Lemeor
  • Think Studio

The Versions

18/02 2018

dev-master

9999999-dev https://github.com/yaroslawww/laravel-force-https

Easy redirect to https for Laravel

  Sources   Download

MIT

The Requires

 

by Yaroslav Georgitsa

laravel https php ssl

18/02 2018

1.1.1

1.1.1.0 https://github.com/yaroslawww/laravel-force-https

Easy redirect to https for Laravel

  Sources   Download

MIT

The Requires

 

by Yaroslav Georgitsa

laravel https php ssl

22/09 2017

1.1.0

1.1.0.0 https://github.com/yaroslawww/laravel-force-https

Easy redirect to https for Laravel

  Sources   Download

MIT

The Requires

 

by Yaroslav Georgitsa

laravel https php ssl

13/08 2017

1.0.11

1.0.11.0 https://github.com/yaroslawww/laravel-force-https

Easy redirect to https for Laravel

  Sources   Download

MIT

The Requires

 

by Yaroslav Georgitsa

laravel https php ssl

07/04 2017

1.0.10

1.0.10.0 https://github.com/yaroslawww/laravel-force-https

Easy redirect to https for Laravel

  Sources   Download

MIT

The Requires

 

by Yaroslav Georgitsa

laravel https php ssl

31/03 2017

1.0.6

1.0.6.0 https://github.com/yaroslawww/laravel-force-https

Easy redirect to https for Laravel

  Sources   Download

MIT

The Requires

 

by Yaroslav Georgitsa

laravel https php ssl

31/03 2017

1.0.0

1.0.0.0 https://github.com/yaroslawww/laravel-force-https

Easy redirect to https for Laravel

  Sources   Download

MIT

The Requires

 

by Yaroslav Georgitsa

laravel https php ssl