You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel Filament本地访问异常:POST方法不支持问题求助

解决Laravel Filament登录POST方法不支持的问题

这是因为直接通过Web服务器(如Apache/Nginx)访问项目根目录下的public子目录时,Laravel的URL重写规则未正确配置,导致POST请求无法被正确路由。而php artisan serve自带的开发服务器已经内置了正确的请求转发逻辑,所以能正常工作。

可以按以下步骤解决:

  • 修改Web服务器文档根目录:将Apache或Nginx的文档根目录直接指向Laravel项目的public文件夹,而非项目根目录。

    • Apache示例(VirtualHost配置):
      DocumentRoot "/path/to/your/laravel-project/public"
      ServerName localhost
      
    • Nginx示例(server块配置):
      root /path/to/your/laravel-project/public;
      index index.php index.html index.htm;
      

    修改后直接访问http://localhost/admin即可,无需在URL中添加public。

  • 临时重写规则(无法修改文档根目录时):

    • Apache:确保启用mod_rewrite模块,在项目根目录创建或修改.htaccess文件,添加以下规则:
      <IfModule mod_rewrite.c>
          RewriteEngine On
          RewriteRule ^(.*)$ public/$1 [L]
      </IfModule>
      
    • Nginx:在server块中添加请求转发规则:
      location / {
          try_files $uri $uri/ /public/index.php?$query_string;
      }
      
  • 清除路由缓存:执行命令php artisan route:clear,确保路由规则是最新状态。

内容的提问来源于stack exchange,提问作者Kudzanai Machemedze

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 05:48:11