4

I have project and I installed SSL certificate on ubuntu server. I have done every solution I found but still getting this message every time I open a page.

The requested URL /about was not found on this server.

Here is what I have changed to force Laravel to use https:

1- I have changed .htaccess in my public folder and added these lines

# Added to Force HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

2- In app->Providers->AppServiceProvider I have add this to boot() function

if (App::environment() === 'production' || App::environment() === 'dev') {
            URL::forceScheme('https');
        }

3- I have created php artisan make:middleware ForceSSL and added the below code to the handle function

 if (!$request->secure() && in_array(env('APP_ENV'), ['stage', 'production'])) {
            return redirect()->secure($request->getRequestUri());
        }

        return $next($request);

and in Kernal.php

\MyApp\Http\Middleware\ForceSSL::class

In .env file I have changed the APP_URL to https:// and I have also changes APP_URL in app.php inside config folder.

What I have missing here? Since two days I couldn't figure out why :(

Miss. Nada
  • 321
  • 1
  • 4
  • 14

2 Answers2

3

There are few things you need to make sure working :

  1. Is your route working in standard HTTP mode without index.php in url. Like sometimes laravel.com/aboutus does no work but laravel.com/index.php/aboutus works. If its the case, you need to enable mod_rewrites in php and then add AllowOverride All in your virtualhost configurations and restart apache.
  2. Coming to HTTPS, what you have setup in laravel will make laravel request forwarded to a secure HTTPS url. However, your server must be able listen, handle and respond to HTTPS request.
  3. You need to enable yoru virtualhost to listen to port 443 which is the SSL port. Also, if you have SSL certificates, those need to be configured as well.
  4. Before knowing if laravel works on HTTPS, make a simple php file and try to access it using HTTPS of the server url. If that works then you can check whats wrong in laravel. If that does not, then SSL is no configured correctly on your server.
  5. Lastly, check .htaccess rewrite conditions.
  6. php artisan config:clear and php artisan route:cache

Hope this helps to debug this

Mihir Bhende
  • 8,677
  • 1
  • 30
  • 37
0

AWS | Centos | EC2 | AWS Certificate

A little bit late, but myself I only had to change this in my env. file :

APP_URL=http://localhost

to

APP_URL=https://localhost

Everything is working smoothly.

marcq
  • 477
  • 3
  • 12