Laravel:如何强制HTTPS? [英] Laravel: how to force HTTPS?

查看:462
本文介绍了Laravel:如何强制HTTPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始开发一个新的大应用程序,这次我正在使用Laravel,这是第一次。

I'm starting to develop a new big app, and I'm using Laravel this time, and it's the first time.

我需要强制使用HTTPS所有页面,如果从代码或.htaccess,它并不重要,但我无法找到一个简单的教程。

I need to force HTTPS for all pages, it's not important if from code or by .htaccess, but I'm not able to find a simple tutorial.

官方文档不会谈论这个问题。

The official docs dosn't speak about this problem.

有关信息,我的实际.htaccess是

For info, my acutal .htaccess is

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

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

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

我的问题是针对Laravel 5的,因为我不知道在哪里以及如何修改这个.htaccess文件。而且我也问你这是否是Laravel的正确方法,或者Laravel是否有特定的设置来处理HTTP。

My question is specific to Laravel 5, because I ve no idea on where and how modify this .htaccess file. And also I'am asking you if this is the right way for Laravel or if Laravel has something specific to setup to handle HTTPs.

所以请不要关闭我的问题,并尝试更加坚持Laravel特定主题。

So please do not close my question and try to be more adherent to the Laravel specific topic.

如果你可以发布一个简单的方法来修改这个文件和/或在Laravel配置中修改什么来正确处理https。

If you can post a simple way to modify this file AND/OR What to modify in Laravel config to properly handle https.

但简而言之,是的,我想强制每次通过HTTPS转接。

But in short yes, I want to force every call to transit on HTTPS.

推荐答案

您需要将其添加到 .htacsses

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://YOURWEBSITEDOMAIN/$1 [R,L]

请参阅:
http://www.inmotionhosting.com/support/website/ssl/how-to-force-https-using-the-htaccess-file

这篇关于Laravel:如何强制HTTPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆