我们使用 Laravel 5。要将 http 连接重定向到 https,请使用中间件 HttpsProtocol。
namespace MyApp\Http\Middleware;
use Closure;
class HttpsProtocol {
public function handle($request, Closure $next)
{
if (!$request->secure() && env('APP_ENV') === 'prod') {
return redirect()->secure($request->getRequestUri());
}
return $next($request);
}
}
在我们的 4 个测试用例中,只有 1 个(最后一次重定向)正确工作。其他3个案例中间件添加url extra index.php。
http://www.aqualink.az/index.php ---> https://www.aqualink.az/index.php/index.php http://aqualink.az/index.php ---> https://aqualink.az/index.php/index.php https://www.aqualink.az/index.php ---> https://www.aqualink.az/index.php/index.php https://aqualink.az/index.php ---> https://aqualink.az/index.php
最佳答案
我用htaccess解决了
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
关于php - Laravel 将 Http 重定向到 Https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39249334/