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

Laravel Livewire在cPanel共享主机上wire指令触发404问题求助

解决Laravel Livewire在cPanel共享主机子目录下的404问题

1. 修正.env中的APP_URL配置

确保.env文件里的APP_URL指向子目录完整地址:

APP_URL=https://ahotosu-susu-enterprise.com/custom

2. 配置Livewire的asset_url

编辑config/livewire.php文件,设置asset_url为子目录的完整URL:

'asset_url' => env('APP_URL'),

若环境变量未生效,可直接硬编码:

'asset_url' => 'https://ahotosu-susu-enterprise.com/custom',

3. 调整cPanel下的.htaccess规则

如果Laravel应用放在custom子目录,需确保根目录和子目录public文件夹的.htaccess规则正确:

根目录(public_html)的.htaccess:

RewriteEngine On
RewriteRule ^$ custom/public/ [L]
RewriteRule (.*) custom/public/$1 [L]

子目录public文件夹下的.htaccess:

保留Laravel默认重写规则即可:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

4. 清除所有缓存

通过SSH或cPanel终端执行命令:

php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan livewire:clear

若无法使用终端,可手动删除bootstrap/cache目录下的所有文件。

5. 确认Livewire脚本配置

确保主布局文件中@livewireScriptConfig放在</body>标签前:

<body>
    <!-- 页面内容 -->

    @livewireScriptConfig
</body>

以上步骤核心是保证子目录路由重写规则正确,以及Livewire资源路径配置准确,可解决wire:click、wire:model触发时的404问题。

内容的提问来源于stack exchange,提问作者Victor Vibist Tetteh

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 23:22:04