将文件上传到主机后 CSS 不起作用

问题描述

我正在使用 yii2 高级项目,我只是将文件上传到托管中。不幸的是,我的网站没有加载资产文件 - 如 CSS 或 js。

可能有一些不好的路径,但我不确定。

有几个类似的错误GET http://myhosting.pl/frontend/web/css/site.css net::ERR_ABORTED 404 (Not Found)

错误与此行有关:<link href="/frontend/web/css/site.css" rel="stylesheet">

我认为这可能是 .htaccess 或类似问题,因为我完全是处理托管文件的新手。我的 .htaccess 看起来像这样:

AddDefaultCharset UTF-8

Options FollowSymLinks
DirectoryIndex index.PHP index.html
RewriteEngine on

RewriteRule /\. - [L,F]

# define the app environment variable
RewriteCond %{REQUEST_URI} !^/((frontend|backend)/views|admin)
RewriteRule ^ - [E=APP:frontend]
RewriteCond %{REQUEST_URI} (?!^/backend/web)^/admin
RewriteRule ^ - [E=APP:backend]

# rewrite the URI of the frontend app
RewriteCond %{ENV:APP} =frontend
RewriteRule ^ frontend/web%{REQUEST_URI}
# if a directory or a file exists,use the request directly
RewriteCond %{ENV:APP} =frontend
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward the request to index.PHP
RewriteRule ^ frontend/web/index.PHP [L]

# redirect to the URL without a trailing slash (uncomment if necessary)
#RewriteRule ^admin/$ /admin [L,R=301]

# rewrite the URI of the backend app
RewriteCond %{ENV:APP} =backend
RewriteRule ^admin/?(.*)$ backend/web/$1
# if a directory or a file exists,use the request directly
RewriteCond %{ENV:APP} =backend
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward the request to index.PHP
RewriteRule ^ backend/web/index.PHP [L]

# handle a directory trailing slash,redirect to the initial URI instead of the rewritten one
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [L,R=301]

我只想补充一点,本地主机上的一切都很好。

另外...我没有使用相对路径,我使用的是 AppAsset,它看起来像这样:

class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        'css/site.css',];
    public $js = [
    ];
    public $depends = [
        'yii\web\YiiAsset','yii\bootstrap\BootstrapAsset',];
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)