A
A
Alexander2015-06-02 08:41:54
Yii
Alexander, 2015-06-02 08:41:54

How to set up on yii2 advanced hosting?

Hi all !!! I'm switching to yii2. How to set up so that when going to the site.local site, the frontend folder opens and does not show all folders, where to set it up? and also current from the backend - site.local/admin - the backend folder was opened.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cache0, 2017-07-16
@kentuck1213

from myself and for myself

# Mod_Autoindex
<IfModule mod_autoindex.c>
  Options -Indexes
</IfModule>

# Mod_Rewrite
<IfModule mod_rewrite.c>
  Options +FollowSymlinks

  RewriteEngine On
  IndexIgnore */*
  RewriteRule ^admin/(.*)?$ /backend/web/$1 [L,PT]

  RewriteRule ^admin(.*)?$ /backend/web/$1 [L,PT] 

  RewriteRule ^([^/].*)?$ /frontend/web/$1
</IfModule>

and this is backend/config/main.php with the transition rule with the word admin in the address and the name of the controller removed, in the frontend everything is similar, just remove . "/admin" from the string 'baseUrl' => $baseUrl . "/admin", and of course, change all the words backend to frontend
<?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')
);
 
use \yii\web\Request;
$baseUrl = str_replace('/backend/web', '', (new Request)->getBaseUrl());
 
return [
    'id' => 'app-backend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'backend\controllers',
 
    'components' => [
 
        'request' => [
            'baseUrl' => $baseUrl . "/admin",
        ],
 
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
        ],
 
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
 
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
 
        'urlManager' => [
            'enablePrettyUrl' => true,
             'showScriptName' => false,
             'suffix'=>'/',
             'rules'=>array(
                 ''=>'site/index',
                 '<action>'=>'site/<action>',
             ),
        ],
    ],
    'params' => $params,
];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question