Hello guys, I have a problem which confusing and disappointing me .
The problem is: after finishing a laravel app and deploying it , everything works fine except for the non secure mark that appears with the url.
I tried so many solution but I haven't figured it yet.
I tried forcing the http to https from my laravel app but It doesn't work and I also tried to use SSL certificate from my hosting and actually It didn't work aswell.
I tried to deploy on different hosts and the problem appear with all of them and that leaded me that the problem in something in the development but I didn't find it out.
I didn't upload my .env and I even set my APP_DEBUG variable to false while deployment.
So please can someone try to help me to figure this out?
i guess that you may need to purchase real SSL certificate from Digicert or any authorized certificate provider to be installed in the production server...
I remember that I once made a middleware to force the route to https and I used this middleware to the login form and when try to login it just redirects back with this error in my console:
Migrate entirely to HTTPS to have cookies sent to same-site subresources
but when i removed the middleware from the login route it works fine.
@Snapey
I'm not using the default middleware by laravel which is TrustHosts. but I acturally use the csrf token in each form i have. Is that a problem?
I am using Laravel 11.42.1, and my Heroku app did the same thing. These were the changes I made to get it to work:
Edit "app/Providers/AppServiceProvider.php" with this code:
<?php
namespace App\Providers;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
// Force HTTPS in non-local environments
if($this->app->environment('production', 'staging')) {
URL::forceScheme('https');
}
}
}
Run this command in the terminal to create a new middleware class:
php artisan make:middleware TrustProxies
Edit "app/Http/Middleware/TrustProxies.php" with this code:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Http\Middleware\TrustProxies as Middleware;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application
*
* @var array|string|null
*/
protected $proxies = '*'; // Trust all proxies (Heroku's dynamic IPs)
/**
* The headers that should be used to detect proxies.
*
* @var int
*/
protected $headers =
Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO |
Request::HEADER_X_FORWARDED_AWS_ELB;
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
return $next($request);
}
}
On Heroku, I set APP_ENV and APP_URL environment variables on my staging and production apps. I ensured the SSL certificate was created and working.