我已将我的Yii2应用程序从localhost移至以下位置的实时服务器
www.mydoamin.com/awpet
awpet是运行应用程序的子域。 另外,我已将以下代码作为index.php
放在awpet目录中<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/common/config/bootstrap.php');
require(__DIR__ . '/frontend/config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/common/config/main.php'),
require(__DIR__ . '/common/config/main-local.php'),
require(__DIR__ . '/frontend/config/main.php'),
require(__DIR__ . '/frontend/config/main-local.php')
);
$application = new yii\web\Application($config);
$application->run();
?>
现在,当我去awpet.mydomain.com时,我收到以下错误 -
资产目录不在awpet
文件夹中。而且我不知道它来自哪里......我已经在awpet/frontend/web
文件夹中拥有资产目录。
我可以访问awpet.mydomain.com/frontend/web/index.php。
awpet /前端/配置/ main.php
<?php
$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',
'name'=>'My AWPET',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'modules' => [
'gridview' => [
'class' => '\kartik\grid\Module'
],
'workpermit' => [
'class' => 'frontend\modules\workpermit\workpermit',
],
],
'controllerNamespace' => 'frontend\controllers',
'components' => [
'request' => [
'csrfParam' => '_csrf-frontend',
],
'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',
],
'authManager' => [
'class' => 'yii\rbac\DbManager',
'defaultRoles' => ['guest'],
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
// 'urlManager' => [
// 'enablePrettyUrl' => true,
// 'showScriptName' => false,
// 'rules' => [
// ],
// ],
],
'params' => $params,
];
如果我遗失了某些内容,请告诉我。
答案 0 :(得分:0)
从index.php中删除您的更改。
打开frontend / config / main.php。
请注意'baseUrl' => '',
行注释掉它。
使用:'scriptUrl' => @$_SERVER['REMOTE_ADDR'] == '127.0.0.1' ? '/index.php' : '/awpet/index.php'
确定。我在前端和后端的版本分离。
项目根目录上的.htaccess
# Mod_Autoindex
<IfModule mod_autoindex.c>
Options -Indexes
</IfModule>
# Mod_Rewrite
<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch
RewriteEngine On
IndexIgnore */*
# Open access to storage directory
RewriteRule ^(admin/)?storage/(.+)$ storage/$2 [L,PT]
RewriteRule ^admin/?([^/].*)?$ backend/web/$1 [L,PT]
RewriteRule ^([^/].*)?$ frontend/web/$1
</IfModule>
.htacces on frontend / web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
.htaccess on backend / web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
前端/配置/ main.php
'request' => [
'scriptUrl' => @$_SERVER['REMOTE_ADDR'] == '127.0.0.1' ? '/index.php' : '/awpet/index.php',
'csrfParam' => '_csrf-frontend',
],
后端/配置/ main.php
'request' => [
'scriptUrl' => @$_SERVER['REMOTE_ADDR'] == '127.0.0.1' ? '/admin/index.php' : '/awpet/admin/index.php',
'csrfParam' => '_csrf-backend',
],
答案 1 :(得分:0)
据我所知,您的子域名awpet.mydomain.com指向 www.mydoamin.com / awpet;
但不应该指向 www.mydoamin.com / awpet / frontend / web?
www.mydoamin.com ...应该是服务器路径;例如:/ root / www / html /..