0

I have a problem like this, and I decided following this tutorial, but in step 1 do I need to add all the folders that are inside the web folder like js, css, img and others?

Is because some features within these folders are not loading..

step 1

Options +FollowSymlinks
RewriteEngine On

# deal with admin first
RewriteCond %{REQUEST_URI} ^/(admin) <------
RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L]
RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L]

RewriteCond %{REQUEST_URI} !^/backend/web/(assets|css)/  <------
RewriteCond %{REQUEST_URI} ^/(admin)  <------
RewriteRule ^.*$ backend/web/index.php [L]


RewriteCond %{REQUEST_URI} ^/(assets|css)  <------
RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
RewriteRule ^js/(.*)$ frontend/web/js/$1 [L] 
RewriteRule ^images/(.*)$ frontend/web/images/$1 [L]

RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css)/  <------
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ frontend/web/index.php
Moutinho
  • 321
  • 3
  • 14

1 Answers1

0

I suggest you to move your backend\web\index.php file to root folder

then rename it to admin.php and change content to:

<?php
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');

require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/vendor/yiisoft/yii2/Yii.php';
require __DIR__ . '/common/config/bootstrap.php';
require __DIR__ . '/backend/config/bootstrap.php';

$config = yii\helpers\ArrayHelper::merge(
require __DIR__ . '/common/config/main.php',
require __DIR__ . '/common/config/main-local.php',
require __DIR__ . '/backend/config/main.php',
require __DIR__ . '/backend/config/main-local.php'
);

(new yii\web\Application($config))->run();

and change .htaccess to:

RewriteOptions inherit
RewriteEngine On
# for backend and control panel
RewriteRule ^admin(.*) admin.php
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

Options -Indexes
DirectoryIndex index.php

your directory must be like this :

  • assets
  • backend // remove web directory from backend
  • common
  • console
  • frontend // and you can remove web directory from frontend too
  • vendor
  • index.php // index of frontend
  • admin.php // index of backend

at the end; www.yoursite.com/site/index => frontend/site/index

www.yoursite.com/admin/site/index => backend/site/index

ttrasn
  • 3,070
  • 4
  • 17
  • 30
  • you can explain?I replace this for my previous code? – Moutinho Dec 24 '18 at 21:52
  • yes, first you must move your backend index file to root directory, then change content to what i said and after that change your htaccess file for redirect your from whatever in url starts with **admin/** to backend (admin.php) – ttrasn Dec 25 '18 at 05:57
  • return erros `An Error occurred while handling another error: yii\base\InvalidConfigException: The directory does not exist: C:/xampp/htdocs/appName/assets in C:\xampp\htdocs\appName\vendor\yiisoft\yii2\web\AssetManager.php:213 Stack trace: #0 C:\xampp\htdocs\appName\vendor\yiisoft\yii2\base\BaseObject.php(108): yii\web\AssetManager->init() #1 [internal function]: yii\base\BaseObject->__construct(Array)...` Another thing remove **backend/web** and place where? i have css, js inside. – Moutinho Dec 25 '18 at 12:37
  • error says **assets** directory is not exist, first of all create it in root directory:) second move your assets file in **backend/web** to assets directory in root (which one you created in last step) – ttrasn Dec 25 '18 at 13:09
  • apparently it works, but I have to put all the content of **backend/web** in root – Moutinho Dec 25 '18 at 14:01
  • @Tiago you can do it :) and you can set **upvote** for my answer :D – ttrasn Dec 25 '18 at 18:46