【问题标题】:yii2 advanced one domain config not workingyii2 高级一个域配置不起作用
【发布时间】:2020-09-14 12:50:08
【问题描述】:

我使用 Xampp,启用了 mod_rewrite(phpinfo 说)

root htAccess

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)/web|szerk)
RewriteRule ^ - [E=APP:frontend]
RewriteCond %{REQUEST_URI} (?!^/backend/web)^/szerk
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 ^szerk/?(.*)$ 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 the rewritten one
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [L,R=301]

我把 backend/web és frontend/web .htaccess, 内容:

RewriteEngine On RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

common/config/main.php

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

后端/config/main.php

return [
    'id' => 'app-backend',
    'language' => 'hu-HU',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'backend\controllers',

    'bootstrap' => ['log'],
    'modules' => [],
    'homeUrl' => '/szerk',
    'components' => [
        'request' => [
            'csrfParam' => '_csrf-backend',
            'csrfCookie' => [
                'httpOnly' => true,
                'path' => '/szerk',
            ],
            'baseUrl' => '/szerk',
        ],
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-backend', 'path' => '/szerk', 'httpOnly' => true],
        ],
        'session' => [
            // this is the name of the session cookie used for login on the backend
            'name' => 'advanced-backend',
            'cookieParams' => [
                'path' => '/szerk',
            ],
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ]
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
        ]
        
    ],

    'aliases'=>[
        '@Imagine'=>'@vendor/Imagine', //this should correspond to pathA above
    ],
    'params' => $params,
];

前端/config/main.php

return [
    'id' => 'app-frontend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'frontend\controllers',
    'components' => [
        'request' => [
            'csrfParam' => '_csrf-frontend',
            'baseUrl' => '',
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
        ],
        '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',
        ],
        'i18n' => [
            'translations' => [
                'app*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@app/messages',
                    //'sourceLanguage' => 'hu-HU',
                    //'fileMap' => [
                    //    'app' => 'app.php',
                    //    'app/error' => 'error.php',
                    //],
                ],
            ],
        ],
        
        
        
    ],
    'params' => $params,
];

当我运行时: yii 服务 --docroot="frontend/web/" --port=8890 然后我可以看到前端页面,图像等......那很好,但是当我输入 url /szerk 我得到 404 not found 当我运行时: yii 服务 --port=8890 总是重定向到 /szerk/login 后端登录页面,但是 css/images 没有加载...

我将如何配置这些东西以使其正常工作? 我在谷歌搜索了两天,但没有任何反应......

它可以在线工作,但在本地主机中没有

【问题讨论】:

    标签: php yii2


    【解决方案1】:

    yii serve 不使用 Apache,因此根本不使用您的配置文件。 配置您的 localhost 以使用 Apache 而不是内部 php 服务器

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-23
      • 1970-01-01
      • 2013-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-19
      相关资源
      最近更新 更多