maxasela
maxasela

Reputation: 347

Laravel HTTP to HTTPS redirection wont work

Have tried so many Solution but nothing work; here is my .htaccess file.

HTTPS website works without issue, for example when i click a Menu or a Logo icon it redirects to https://abc123.com but when i delete s from https and type HTTP://abc123.com it wont redirect..

I have used Laravel 8.8 in PHP 7.4 environment,Have recently moved to PHP 8 also..but nothing seems to work,

Have tried the


namespace App\Providers;

use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        URL::forceScheme('https');
    }
}

But this only result in 500 error..

What I am missing here?


RewriteEngine on
RewriteCond %{HTTP_HOST} abc123.com\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://abc123.com/$1 [R,L]
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]


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


# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{HTTP_HOST} ^abc123\.com [NC]
# RewriteCond %{SERVER_PORT} 80
# RewriteRule ^(.*)$ https://abc123.com/$1 [R,L]

# Header always set Content-Security-Policy: upgrade-insecure-requests
# RewriteEngine On
# RewriteCond %{HTTPS} !=on
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# BEGIN Expire headers  
<IfModule mod_expires.c>  
  # Turn on the module.
  ExpiresActive on
  # Set the default expiry times.
  ExpiresDefault "access plus 2 days"
  ExpiresByType image/jpg "access plus 1 month"
  ExpiresByType image/svg+xml "access 1 month"
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType application/x-shockwave-flash "access plus 1 month"
  ExpiresByType image/ico "access plus 1 month"
  ExpiresByType image/x-icon "access plus 1 month"
  ExpiresByType text/html "access plus 600 seconds"
</IfModule>  
# END Expire headers
# RewriteEngine On
# RewriteCond %{HTTP_HOST} abc123\.com [NC]
# RewriteCond %{SERVER_PORT} 80
# RewriteRule ^(.*)$ https://abc123.com/$1 [R,L]



#RewriteEngine On
#RewriteCond %{HTTP_HOST} abc123.com\.com [NC]
#RewriteCond %{SERVER_PORT} 80
#RewriteRule ^(.*)$ https://abc123.com/$1 [R,L]


<IfModule mime_module>
  AddHandler application/x-httpd-ea-php80 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

Have commented what i have tried so far,,Maybe i am missing something.

Upvotes: 0

Views: 369

Answers (1)

maxasela
maxasela

Reputation: 347

I have sorted out the issue..for future reference, I am posting the answer here.

RewriteEngine on
RewriteCond %{HTTPS} !=on   
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This has solved my question.

Upvotes: 1

Related Questions