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

移除URL中public后Laravel File Manager无法加载CSS/JS文件求助

Fixing Laravel File Manager After Removing public From URLs

Hey there! I’ve run into this exact issue before—removing the public segment from Laravel URLs can throw off asset paths and route handling for packages like Laravel File Manager. Let’s walk through the fixes step by step:

1. First, Verify Your Server Configuration is Correct

Removing public from the URL doesn’t mean deleting the public folder—it means configuring your web server to point its root directory directly to your Laravel project’s public folder. If this isn’t set up right, all asset paths and routes will break.

For Apache:

Make sure your project root has an .htaccess file (not just the one in public) with this content:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Or better yet, configure your virtual host to set DocumentRoot to /path/to/your/project/public.

For Nginx:

Update your server block to point the root to the public folder:

server {
    listen 80;
    server_name yourdomain.com;
    root /path/to/your/project/public;

    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; # Adjust PHP version to match yours
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

2. Check Laravel File Manager’s Configuration

Open config/lfm.php and verify these key settings:

  • 'url_prefix' => 'laravel-filemanager': This should match the prefix you used when registering the routes (usually /laravel-filemanager). Since your server now serves from the root, this prefix should work without needing public in front.
  • 'disk' => 'public': Ensure your filesystems config (config/filesystems.php) has the public disk set up correctly, with matching url and root paths.

3. Fix Static Asset Paths

If you tried manually adding CSS/JS files and they still don’t load, stop hardcoding paths—use Laravel’s asset() helper instead. It automatically generates the correct path relative to your server’s root (which now points to public):

<link rel="stylesheet" href="{{ asset('vendor/laravel-filemanager/css/lfm.css') }}">
<script src="{{ asset('vendor/laravel-filemanager/js/lfm.js') }}"></script>

4. Clear All Caches

Laravel might be holding onto old asset paths or route configurations. Run these commands in your project root:

php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear

Also, force-refresh your browser (Ctrl+F5 or Cmd+Shift+R) to clear local cache.

5. Verify Route Registration

Double-check that your File Manager routes are registered correctly in routes/web.php:

Route::group(['prefix' => 'laravel-filemanager', 'middleware' => ['web', 'auth']], function () {
    \UniSharp\LaravelFilemanager\Lfm::routes();
});

Make sure the prefix matches the url_prefix in config/lfm.php, and that the middleware (like auth) fits your project’s needs.

If you’re still stuck, open your browser’s developer tools (Network tab) to check for 404 errors—this will show you exactly which paths are incorrect, making it easier to fix the final kinks.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 07:16:35