0

I'm trying to redirect http to

https://www.example.com

in laravel 5.2

trying to do it using middlware Please see code

In karnel.php

\App\Http\Middleware\HttpsProtocol::class,

middlware

public function handle($request, Closure $next)

{
   $url = 'https://www.example.com';
    if (!$request->secure()) {
        return redirect()->secure($url);
    }
    return $next($request);
}

but getting error

ERR_TOO_MANY_REDIRECTS

And when try to do it using .htaccess

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

RewriteEngine On


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

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

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

it will redirect to

https://www.www.example.com

What i want is if anyone type domain.com then it will automatically redirect to

https://www/example.com

in laravel 5.2

V001
  • 43
  • 12
  • You are probably looping through the handle method why causing amounts of redirects – utdev Oct 04 '19 at 07:27
  • Follow to [my answer here](https://stackoverflow.com/questions/58209607/err-too-many-redirects-when-redirecting-to-non-www-https-in-laravel/58210357#58210357) (actually the last part). I think that's what you want – boolfalse Oct 04 '19 at 07:33
  • See this link: [https://stackoverflow.com/questions/28402726/laravel-5-redirect-to-https](https://stackoverflow.com/questions/28402726/laravel-5-redirect-to-https) – Hossein.Kiani Oct 04 '19 at 08:40

0 Answers0