htaccess for frontend and backend

Hi team,

I have created an application with both frontend and backend.

If i hit the url http://www.url.com/crm , i have to access the frontend application and if i hit the url http://www.url.com ,I have to access the backend by default. sessions should be shared for both frontend and backend.

My root htaccess is :




Options -Indexes


<IfModule mod_rewrite.c> 


  RewriteEngine on 


  RewriteCond %{HTTPS} off


  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]


  RewriteCond %{REQUEST_URI} /(crm)


  RewriteRule ^(.*)$ frontend/web/$1 [L] 


  RewriteCond %{REQUEST_URI} !^/(frontend/web|crm)

 

  RewriteRule ^(.*)$ backend/web/$1 [L] 


#  RewriteCond %{REQUEST_URI} 


#  RewriteRule ^(.*)$ backend/web/$1 [L] 

  

</IfModule>


# Deny accessing below extensions

#<Files ~ "(.json|.lock|.git)">

#Order allow,deny

#Deny from all

#</Files>


# Deny accessing dot files

RewriteRule (^\.|/\.) - [F]




My frontend config/main.php is





<?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;


//echo (new Request)->getBaseUrl();exit;


 $baseUrl = str_replace('/frontend/web', '/crm', (new Request)->getBaseUrl());


//exit;

//echo dirname(__DIR__);exit;


//$baseUrl = (new Request)->getBaseUrl();


return [

    'id' => 'app-frontend',

    'basePath' => dirname(__DIR__),

    'bootstrap' => ['log'],

    'controllerNamespace' => 'frontend\controllers',

    'components' => [

        'request' => [

            'csrfParam' => '_csrf-frontend',

            'baseUrl' => $baseUrl,

        ],

        'user' => [

            'loginUrl' => ['../user/login'],  

            

        ],


        'log' => [

            'traceLevel' => YII_DEBUG ? 3 : 0,

            'targets' => [

                [

                    'class' => 'yii\log\FileTarget',

                    'levels' => ['error', 'warning'],

                ],

            ],

        ],

        'errorHandler' => [

            'errorAction' => 'site/error',

        ],

        'urlManager' => [

            'class' => 'yii\web\UrlManager',

            'baseUrl' => $baseUrl,

            'enablePrettyUrl' => true,

            'showScriptName' => false,

            'rules' => []

        ],

    ],

    'params' => $params,

];




and my backend config/main.php is







<?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__),

    'controllerNamespace' => 'backend\controllers',

    'bootstrap' => ['log'],

    'modules' => [

        

        'user' => [

            'class' => 'dektrium\user\Module',

            'modelMap' => [

                'User' => 'backend\models\User',

            ],

            'controllerMap' => [

                'admin' => 'app\controllers\user\AdminController',

                'recovery' => 'app\controllers\user\RecoveryController',

                'registration' => 'app\controllers\user\RegistrationController',

                'security' => 'app\controllers\user\SecurityController',

            ],

            'admins' => ['superadmin']

        ],

    ],

    'components' => [

        

        'request' => [

            'csrfParam' => '_csrf-backend',

            'baseUrl' => $baseUrl,

        ],

        

//        'assetManager'=>[

//            'basePath'=>(new Request)->getBaseUrl().'/assets',

//        ],

            

        'view' => [

            'theme' => [

                'pathMap' => [

                    '@dektrium/user/views' => '@app/views/user',

                ],

            ],

        ],

        'session' => [

            // this is the name of the session cookie used for login on the backend

            'name' => 'advanced-backend',

        ],

        

        'errorHandler' => [

            'errorAction' => 'site/error',

        ],

        'urlManager' => [

            'class' => 'yii\web\UrlManager',

            'baseUrl' => $baseUrl,

            'enablePrettyUrl' => true,

            'showScriptName' => false,

            'rules' => []

        ],

    ],

    'params' => $params,

];




Please let me know the workaround for this setup.

Thank you,

saran.

This setup is working in Xampp if i place

$baseUrl = str_replace(’/frontend/web’, ‘’, (new Request)->getBaseUrl()).’/crm/’; in frontend/config/main.php.

But we are having error when i uploaded the application to cpanel account.