HTTPS : error when forcing https via .htaccess , or forceScheme or Middleware

Published 2 months ago by hzuluaga

Hello I have installed ssl certificate on Apache /CentOs6 and it works. I modified .htaccess file within my laravel/public folder in order to force https requests. however , apart form the login page that is displayed correctly (with the https url) , after authentication is done, the server responds with the following error:

Not Found
The requested URL /login was not found on this server.
Apache/2.2.15 (CentOS) Server at Port 443

this is my .htaccess:

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

RewriteEngine On

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

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

# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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

Same happens if I force https via \URL::forceScheme('https') . called in AppServiceProvider.php or using middleware :

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());


        return $next($request);

What am I missing ? thx any help ...


I found the reason of the error ..I had to add some directives inside the virtualhost for port 443

<VirtualHost *:443>
<Directory "/var/www/html/siterootdir">
        Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all


Please sign in or create an account to participate in this conversation.