A
A
Alexander2016-02-18 09:54:39
Yii
Alexander, 2016-02-18 09:54:39

How to fix the error: Internal Server Error (Yii advanced)?

In the main directory, I created a .htaccess file with the given codes in the inside:

# prevent directory listings
Options -Indexes
# follow symbolic links
Options FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_URI} ^/admin/$
RewriteRule ^(admin)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin(/.+)?$ /backend/web/$1 [L,PT]

RewriteCond %{REQUEST_URI} ^.*$
RewriteRule ^(.*)$ /frontend/web/$1

in backend/web/ and frontend/web .htaccess folder
# use mod_rewrite for pretty URL support
RewriteEngine on
# if a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward the request to index.php
RewriteRule . index.php

In general, everything is as in this article mickgeek.com/yii-2-advanced-template-on-the-same-d...
In XAMP on Windows it worked, but on Linux LAMP does not plow.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Sanych, 2016-02-18
@kentuck1213

enable mod_rewrite on apache

M
Maxim Timofeev, 2016-02-18
@webinar

See apache logs.
But it's better to move the contents of frontend/web to the root of the public folder, create a subdomain for the backend and move the contents of backend/web there. And throw everything else into the "yii" folder and raise it to a level above the public folder. At the same time, .htaccess will not have to be tortured, this is enough:

RewriteEngine on

# hide files and folders
RedirectMatch 404 /\.git
RedirectMatch 404 /composer\.
RedirectMatch 404 /.bowerrc
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php

It will only be necessary to correct the paths in index.php, here is an example:
<?php
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');

require(__DIR__ . '/../yii/vendor/autoload.php');
require(__DIR__ . '/../yii/vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../yii/common/config/bootstrap.php');
require(__DIR__ . '/../yii/frontend/config/bootstrap.php');

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

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

You will get something like this structure:
-yii
--frontend
--backend
--common
--vendor
-public_html
--admin
---css
---js
---images
---index.php
---.htaccess
--css
--js
--images
--index.php
--.htaccess

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question