0

I am beginner in Laravel. I use in my project Laravel 5.8. This is my htacess:

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

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

How can I make redirect from http://name.com, http://www.name.com, https://www.name.com to https://name.com?

It's posible in htacess or Middleware?

goslscs
  • 187
  • 1
  • 2
  • 10
  • 1
    Possible duplicate of [Laravel 5 - redirect to HTTPS](https://stackoverflow.com/questions/28402726/laravel-5-redirect-to-https) – aldrin27 Aug 06 '19 at 06:52

2 Answers2

0

You can use this in your .htaccess

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Zadat Olayinka
  • 441
  • 3
  • 8
0

Here is .htaccess snippet for force redirect HTTP to https

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / Options +SymLinksIfOwnerMatch ​ RewriteCond %{HTTPS} =on RewriteRule ^ - [env=proto:https] ​ RewriteCond %{HTTPS} !=on RewriteRule ^ - [env=proto:http] ​ RewriteCond %{REQUEST_URI} "!(^|/)\.well-known/([^./]+./?)+$" [NC] RewriteCond %{SCRIPT_FILENAME} -d [OR] RewriteCond %{SCRIPT_FILENAME} -f RewriteRule "(^|/)\." - [F] ​ RewriteCond %{HTTP_HOST} ^domainname\.com$ [NC] RewriteRule ^(.*)$ http://domainname.com$1 [R=301,L] ​ RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://domainname.com/$1 [R,L] ​ ​ ​ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] ​ </IfModule>

PHP Ninja
  • 1,055
  • 2
  • 9
  • 28