php - 在 Laravel 中使用 https 会抛出 apache 错误

标签 php apache laravel-4

我正在努力确保我的 Laravel 项目中使用的所有路由都使用 https

我尝试通过在 `filter.php 文件的 App::before() 过滤器中添加一个重定向来做到这一点,如下所示:

if (!Request::secure()){
    return Redirect::secure(Request::path());
}

这确实重写了我的 url 以使用 https 而不是 http,但是页面返回时出现 Apache 错误:

Not Found

The requested URL /register was not found on this server.

Apache/2.4.9 (Ubuntu) Server at beta.mysite.com Port 443

我还需要更改其他内容以允许 Laravel 看到 https 请求吗?

编辑:这是我当前的 .htaccess 文件的内容:

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

    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://beta.mysite.com/$1 [R,L]
</IfModule>

最佳答案

我遇到的问题实际上是 https 站点的虚拟主机中缺少配置项。

<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerAdmin webmaster@localhost                                                                       

                DocumentRoot /var/www/public


                # The section I was missing START
                <Directory />                                                                                         
                        Options FollowSymLinks                                                                        
                        AllowOverride None                                                                            
                </Directory>                                                                                          

                <Directory /var/www/>                                                                                 
                        Options -Indexes FollowSymLinks MultiViews                                                    
                        AllowOverride All                                                                             
                        Order allow,deny
                        allow from all
                </Directory>
                # The section I was missing End


...

这些规则与在 http 虚拟主机(端口 80)中找到的规则相同。如果没有这些,laravel 就无法获取正确的路线。

一旦我为端口 443 设置好这些,常规 url 就可以使用 https,例如http://beta.mysite.com/registerhttps://beta.mysite.com/register 会路由到同一个地方。

有了这个,默认的 .htaccess 文件和安全路由重定向就可以工作了。

关于php - 在 Laravel 中使用 https 会抛出 apache 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24334397/

相关文章:

php - Facebook:如何解析访问 token 字符串

JavaScript:如何清除我的自定义键盘映射并使用默认键盘映射

php - mb_substr 不能在 PHP 5.2.6 上使用

c++ - 无法在 Windows 上编译 Apache 2.0.63

mysql - Laravel 查询以获得至少包含一个数组元素的结果?

php - 拉维尔 4 : Nest view inside layout with data

java - Android - 如何使用登录名和密码正确查询在线数据库?

python - StreamHandler - 不记录到 docker 容器中的 sys.stdout - Python

php - 如何使用 <a> 标签发布到表单并传递隐藏值?

html - 最好的处理方式包括在子目录中?