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

Published 4 days 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 elinforme.jepcolombia.org Port 443

this is my .htaccess:

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

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]
</IfModule>

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 ...

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