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

Filament/Livewire部署至cPanel及本地子目录时404问题求助

解决Filament + Livewire部署及子目录运行的404问题

一、cPanel部署时livewire.js 404的修复

  • 先确认Laravel的public目录是否正确设为cPanel的网站根目录(通常是public_html)。不少cPanel用户会直接把整个Laravel项目传到根目录,这会导致静态资源路径出错,必须把public文件夹里的所有文件移到public_html,或者修改cPanel的网站根目录指向项目的public文件夹。
  • 清除缓存:通过cPanel终端或SSH执行以下命令:
    php artisan config:clear
    php artisan cache:clear
    php artisan view:clear
    php artisan livewire:publish --assets
    
  • 检查.env文件里的APP_URL是否设为你的域名(比如https://yourdomain.com),注意不要加末尾的斜杠。

二、POST livewire/update 404的解决

  • 确认Laravel的路由重写规则配置正确:在public/.htaccess文件中添加或确保存在以下规则(Apache服务器):
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^(.*)$ public/$1 [L]
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    </IfModule>
    
    若使用Nginx(部分cPanel支持),需配置Nginx的location规则:
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
  • 检查routes/web.php里是否有和livewire/update冲突的自定义路由,避免拦截Livewire的请求。
  • 重新生成路由缓存:
    php artisan route:clear
    

三、本地子目录(http://localhost/myfolder)运行异常的修复

  • 将Laravel项目放在myfolder目录下,然后在项目根目录创建或修改.htaccess,添加重写规则指向public目录:
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^(.*)$ public/$1 [L]
    </IfModule>
    
  • 修改public/.htaccess文件,调整重写规则适配子目录:
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /myfolder/
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    </IfModule>
    
  • 更新.env文件的APP_URL为http://localhost/myfolder,然后执行前面的缓存清除命令。
  • 确保本地服务器(如XAMPP/WAMP)启用了mod_rewrite模块,且Apache配置文件中对应目录的AllowOverride All已设置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 08:30:15