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

查看:61
本文介绍了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 是否有特定的设置来处理 HTTPs.

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.

推荐答案

您需要将此添加到您的 .htaccess 文件中:

You need adding this to your .htaccess file:

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天全站免登陆