I'm using yii2 advanced project, and I just uploaded files into the hosting. Unfortunately, my web is not loading the assets files - like CSS or js.
Probably there is some bad pathing but I'm not sure.
There are a couple of errors similar to that:
GET http://myhosting.pl/frontend/web/css/site.css net::ERR_ABORTED 404 (Not Found)
and that error is connected with this line: <link href="/frontend/web/css/site.css" rel="stylesheet">
I'm thinking that could be a problem with .htaccess or something like that cause I'm totally newbie in working on hosted files. My .htaccess looks like that:
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]
I will just add, that everything was fine on the localhost.
Also...I'm not using the relative paths, I'm using the AppAsset, and it looks like that:
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',
];
}