S
S
Sa7ha_S2017-11-08 21:21:14
htaccess
Sa7ha_S, 2017-11-08 21:21:14

How to redirect from http to https using .htaccess in Laravel framework on Heroku?

There is such a .htaccess file:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>


And there is such a route in Laravel:
Route::get('/', ['https', 'uses' => '[email protected]', 'as' => 'Index']);

On the local server, the redirect works, but on Heroku I can’t get to the https route.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sa7ha_S, 2017-11-09
@Sa7ha_S

There is a solution)
Add the following line to AppServiceProvider.php, to the register method:
$this->app['request']->server->set('HTTPS', true);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question