Laravel强制HTTPS与现代重写 [英] Laravel Forcing HTTPS with Mod Rewrite

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

问题描述

我在运行Laravel 3一个网站,需要强制使用Apache配置以下重写规则的https:

 的RewriteCond%{} HTTPS关闭
重写规则HTTPS(。*)://%{HTTP_HOST}%{REQUEST_URI}

这力量HTTPS正确,但所有的Laravel路由返回未找到(即不打的index.php),如果我删除重写规则一切正常。

在/公共文件夹中的的.htaccess是正常的Laravel:

 < IfModule mod_rewrite.c>
     选择了FollowSymLinks +
     RewriteEngine叙述在
< / IfModule>#针对文件系统中没有找到的所有文件,重新路由请求到
#的index.php前端控制器,保持查询字符串完好< IfModule mod_rewrite.c>
    的RewriteCond%{} REQUEST_FILENAME!-f
    的RewriteCond%{} REQUEST_FILENAME!-d
    重写规则^(。*)$的index.php / $ 1 [L]
< / IfModule>


解决方案

几个小时的调试后,它现在似乎很简单:我的默认的SSL配置没有行

 所有的AllowOverride

要启用htaccess的读取

I have a site running Laravel 3 which needs to force https using the following rewrite rule in apache config:

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

This forces https correctly but all the Laravel routes return 'Not Found' (i.e. not hitting index.php), if I remove the rewrite rule everything works.

The .htaccess inside the /public folder is as normal for Laravel:

<IfModule mod_rewrite.c>
     Options +FollowSymLinks
     RewriteEngine On
</IfModule>

# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

解决方案

After some hours debugging it seems simple now: my default-ssl config did not have the line

AllowOverride All

To enable the htaccess to be read

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

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