1

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',
    ];
}
vishuB
  • 4,173
  • 5
  • 31
  • 49
GimpFather
  • 53
  • 4
  • 1
    You may need to use base tag to fix your js and other relative resources. If you are linking js files using a relative path then the file will obviously get a 404 because its looking for URL path. for example if the URL path is /file/ instead of file.html then your relative resources are loading from /file/ which is not a directory but rewritten html file. To fix this make your links absolute or use base tag. In the header of your webpage add this `` so that your relative links can load from the correct location. – RavinderSingh13 Jul 13 '21 at 10:28
  • I'm not using relative paths. I'm using the appAsset. – GimpFather Jul 13 '21 at 10:45
  • Refer [Yii2 htaccess - How to hide frontend/web and backend/web COMPLETELY](https://stackoverflow.com/questions/28118691/yii2-htaccess-how-to-hide-frontend-web-and-backend-web-completely) – vishuB Jul 13 '21 at 11:36

0 Answers0