Yii2 找不到资产

Yii2 not found assets

Yii2 未找到资产。

设置从地址/frontend/web到站点根目录的转发。

.htaccets

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /    
    RewriteCond %{REQUEST_URI} ^/(admin)
    RewriteRule ^admin/assets/(.*)$ backend/web/assets/ [L]
    RewriteRule ^admin/css/(.*)$ backend/web/css/ [L]
    RewriteRule ^admin/js/(.*)$ backend/web/js/ [L]
    RewriteCond %{REQUEST_URI} !^/backend/web/(assets|js|css|js)/
    RewriteCond %{REQUEST_URI} ^/(admin)
    RewriteRule ^.*$ backend/web/index.php [L]
    RewriteCond %{REQUEST_URI} ^assets
    RewriteRule ^assets/(.*)$ frontend/web/assets/ [L]
    RewriteCond %{REQUEST_URI} ^css
    RewriteRule ^css/(.*)$ frontend/web/css/ [L]
    RewriteCond %{REQUEST_URI} ^js
    RewriteRule ^js/(.*)$ frontend/web/js/ [L]
    RewriteCond %{REQUEST_URI} ^images
    RewriteRule ^images/(.*)$ frontend/web/images/ [L]
    RewriteRule ^(.*)$ frontend/web/ [L]
    RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js)/
    RewriteCond %{REQUEST_URI} !index.php
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ frontend/web/index.php
</IfModule>

main.php

'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [
        '' => 'site/index',         
        '<action>'=>'site/<action>',
    ],
],
    'assetManager' => [
         'basePath' => '@webroot/assets',
         'baseUrl' => '@web/assets'
    ],  
    'request' => [
        'baseUrl' => ''
    ]

一切正常,但样式不行。

这对我有用,试试看

 Options +FollowSymlinks
RewriteEngine On

# deal with administrator first
RewriteCond %{REQUEST_URI} ^/projects/YiiRestful/(administrator)
RewriteRule ^administrator/assets/(.*)$ backend/web/assets/ [L]
RewriteRule ^administrator/css/(.*)$ backend/web/css/ [L]

RewriteCond %{REQUEST_URI} !^/projects/YiiRestful/backend/web/(assets|css)/
RewriteCond %{REQUEST_URI} ^/projects/YiiRestful/(administrator)
RewriteRule ^.*$ backend/web/index.php [L]


RewriteCond %{REQUEST_URI} ^/projects/YiiRestful/(assets|css|images)
RewriteRule ^assets/(.*)$ frontend/web/assets/ [L]
RewriteRule ^css/(.*)$ frontend/web/css/ [L]
RewriteRule ^js/(.*)$ frontend/web/js/ [L] 
RewriteRule ^images/(.*)$ frontend/web/images/ [L]

RewriteCond %{REQUEST_URI} !^/projects/YiiRestful/(frontend|backend)/web/(assets|css|images)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ frontend/web/index.php

前端配置

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'suffix' => '.html',
            'rules' => [
            ],
        ],

      //access Frontend from backend
        'urlManagerFrontend' => [
            'class' => 'yii\web\urlManager',
            'baseUrl' => '@frontend/web',
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                //['?r=site%2Fconcept' => '/site/concept']
            ],
        ],

common/config/bootstrap.php

Yii::setAlias('@common', dirname(__DIR__));
Yii::setAlias('@frontend', dirname(dirname(__DIR__)) . '/frontend');
Yii::setAlias('@backend', dirname(dirname(__DIR__)) . '/backend');

后端配置

'request' => [
            'csrfParam' => '_csrf-backend',
            'class' => 'common\components\Request',
            'web'=> '/backend/web',
            'adminUrl' => '/administrator'
        ],

'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
        ],
    ],

    //access Frontend from backend
    'urlManagerFrontend' => [
        'class' => 'yii\web\urlManager',
        'baseUrl' => 'http://localhost/projects/YiiRestful',
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            //['?r=site%2Fconcept' => '/site/concept']
        ],
    ],