我應用了漂亮的URL並從URL中刪除了前端/網頁,但圖像無法正常工作。Yii2刪除前端/網頁後不顯示圖片
幫助在前端訪問圖像
我已經請參閱本url創建漂亮的URL
代碼:MYAPP /的.htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/myapp/(assets|css|images)
RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
RewriteCond %{REQUEST_URI} !^/myapp/(frontend|backend)/web/(assets|css)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ frontend/web/index.php/$1 [L]
代碼:/ MyApp的/ frontend/config/main.php
use \yii\web\Request;
$baseUrl = str_replace('/frontend/web', '', (new Request)->getBaseUrl());
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-frontend',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'frontend\controllers',
'components' => [
'request' => [
'csrfParam' => '_csrf-frontend',
'class' => 'common\components\Request',
'web'=> '/frontend/web'
],
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
],
'session' => [
// this is the name of the session cookie used for login on the frontend
'name' => 'advanced-frontend',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<alias:login|logout|signup>' => 'site/<alias>',
'users'=>'user/index',
],
],
],
'params' => $params,
];
我試過這個,但得到404錯誤沒有找到圖片 – Kailas
可以請你告訴我究竟是什麼路,它會顯示現在 –