【发布时间】:2026-02-11 10:50:02
【问题描述】:
我正在努力确保我的 Laravel 项目中使用的所有路由都使用 https。
我尝试通过在 `filter.php 文件中的 App::before() 过滤器中添加重定向来做到这一点,如下所示:
if (!Request::secure()){
return Redirect::secure(Request::path());
}
这肯定会重写我的网址以使用 https 而不是 http,但页面返回时出现 Apache 错误:
找不到
在此服务器上找不到请求的 URL /register。
Apache/2.4.9 (Ubuntu) 服务器位于 beta.mysite.com 端口 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正确设置为使用与您的非https站点相同的DocumentRoot? -
是的,我的证书指向
DocumentRoot /var/www/public,这是非http访问的文档根目录。 -
“我的证书正在指向”你是什么意思?基本上,您的
http端口 80 配置需要与您的https端口 443 配置 100% 相同。 -
对不起,我误解了你的问题。我的 443 端口肯定与我的非 https 端口设置相同。当我转到它加载的 index.php 页面时,我应该添加,但是当我尝试访问 laravel 中的任何其他路由时,我得到了上述错误。
-
“在此服务器上找不到请求的 URL /register。”您是否 100% 确定您的
.htaccess已设置为https设置?