如上所述,样式、字体和 js 不会加载到部署在共享主机上的 laravel 上。它在我的本地主机上看起来怎么样:
这与托管上部署的代码相同:
我从哪里获取的:
,
这就是我告诉我编码路径的方式:
<link rel="stylesheet" href="{{ asset('styles/style.css') }}">
<script src="{{ asset('js/main-page.js') }}"></script>
<link href="https://fonts.cdnfonts.com/css/agency-fb" rel="stylesheet">
首先我以为只是公共文件夹没有加载,但后来我意识到字体也没有加载 - 这是从 https 链接获取的,而不是从我的公共文件夹中获取的。有任何想法吗? 我的配置/文件系统.php:
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'throw' => false,
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
],
这是我的控制台日志
当你打开它时,只是一个简单的404
我知道,只是不知道为什么是404。
我尝试在共享主机上部署 Laravel 驱动的代码。我是怎么做到的?通过 installatron 安装最新的 laravel,复制我的文件,需要 laravel/livewire,composer 更新,composer dump-autoload。
我想我已经尝试了一切。将 AppServiceProvider.php 内容更改为
public function boot()
{
if (env('APP_ENV') !== 'local') {
URL::forceScheme('https');
}
}
将资产与私人资产搞乱,实际上我发现的所有东西都不起作用。也许我的文件结构有问题?看起来像这样:
解决了,modyfing .htaccess 对我有用。里面:
# Prevent direct access to the "public" folder - redirect to root
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /public/
RewriteRule ^public/(.*) /$1 [R=302,L]
# Redirect Trailing Slashes If Not A Folder...
# - but look for the file in the "public" folder
# (ensure we are not already in the "public" folder)
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{DOCUMENT_ROOT}/public/$1 !-d
RewriteRule ^(.*)/$ /$1 [R=302,L]
# Rewrite "everything" to the "public" subdirectory if not already
# This ignores existing files/dirs in the document root
RewriteCond %{REQUEST_URI} ^/(.*)
RewriteRule !^public/ public/%1
# Handle Front Controller... (as before)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
来源:https://www.brixly.help/article/25-how-do-i-load-laravel-from-the-public-directory-using-htaccess