L
L
lemonlimelike2018-12-24 23:13:45
Apache HTTP Server
lemonlimelike, 2018-12-24 23:13:45

How to allow http traffic and change all http requests to https in Laravel?

Hello! I have two problems. Uploaded my project to the server (apache). Connected cloudfare, connected ssl. The site is now on https. And then the errors started:
1) For example, there is a form, I specify in the action {{route('action')}}, and this route transfers to http, and such an error pops up

Заблокирована загрузка смешанного активного содержимого «http://
, but if you specify a normal path in action, that is /action, then the request will go through https, so how to fix it so that the named route goes through https? This only happens with roots when I specify their name in the path, like this: <form action="{{route('name_route')}}"></form>or when I use an axios request and in the Url I specify {{route('name_route')}}. That is, such roots use the http protocol, but you need https.
2) A script is connected on the site that goes only via the http protocol, and my site is on the https protocol. And this script refuses to work because of this. How can I make the server skip this script?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Shapoval, 2018-12-25
@lemonlimelike

In the file with routes, write
URL::forceScheme('https');

B
Barmunk, 2018-12-25
@Barmunk

1. Create a global http to https proxy

<?php

namespace App\Http\Middleware;

use Closure;

class HttpsProtocol
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!$request->secure()) {
            return redirect()->secure($request->getRequestUri(), 301);
        }

        return $next($request);
    }
}

2. in env change http to https
by default project use {{route('action')}} for https
On the second problem it looks like a bug, it's better to study it separately than substitute crutches for the framework

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question