Decided to learn php framework - Yii2.
But faced with the problem of routing.

Here is what I have:

config / web.php

... 'components' => [ 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'enableStrictParsing' => true, 'rules' => [ '/' => 'site/say', 'site/contact' => 'site/say' ] ], ... 

.htaccess

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php [L] 

controllers / SiteController.php

 ... public function actionSay($message = 'Привет') { return $this->render('say', ['message' => $message]); } ... 

views / site / say.php

 <?php use yii\helpers\Html; $this->title = 'Say'; ?> <?= Html::encode($message) ?> 

The localhost root points to the basic/web directory. At the request of localhost everything starts normally, the say template is displayed, but at the request of localhost/site/contact error 404 is displayed, the page was not found.

What could be the problem?

  • A. Htaccess in the web folder is? - pa3py6aka
  • yes, exactly there! - Roman Gerasimovich
  • Does the debugger work? bottom of the page which. There may be something to see. - pa3py6aka
  • already found a solution. just apache2 did not allow to apply .htaccess - Roman Gerasimovich

1 answer 1

found a solution.

it was necessary to properly configure apache2 in the apache2.conf file in the description of the directory settings, you had to specify AllowOverride All, something like this

 <Directory /home/.../basic/web> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> 

this allows you to use everything that is written in .htaccess