当服务器在 https 上运行时 url() 返回 http

sim*_*ns3 2 url https laravel

https我在网站示例上使用 laravel 创建一个网络: https://examples.com。我有一个刀片视图,它具有form对另一个页面的操作,https://examples.com/next 我在我的刀片文件中使用了它:<form action="{{url("next")}}" method="POST" id="page">

但是当我在浏览器上测试时,它会显示如下警告: Mixed Content: The page at 'https://examples.com' was loaded over a secure connection, but contains a form that targets an insecure endpoint 'http://examples.com/next'. This endpoint should be made available over a secure connection.

当我检查时<form>,它显示<form action="http://examples.com/next" method="POST" id="page">

有人对此有想法吗?谢谢

N69*_*69S 7

url()laravel 中的 helper 根据请求的协议自动使用 http/https。如果页面是,https://examples.com它应该生成https链接。

如果存在切换协议的代理,则可能会发生该错误。在这种情况下,你有两个选择。

本地解决方案

<form action="{{secure_url("next")}}" method="POST" id="page">
Run Code Online (Sandbox Code Playgroud)

全球解决方案

<form action="{{secure_url("next")}}" method="POST" id="page">
Run Code Online (Sandbox Code Playgroud)

  • @user3532758 使用 CLI 生成 url 时,会使用 `.env` 文件中的 `APP_URL`,在请求模式 (fpm) 下,它将使用 `$_SERVER` 变量并从中生成链接。 (2认同)