F
F
First Name2017-05-18 21:43:49
Yii
First Name, 2017-05-18 21:43:49

How to properly set up CNC in Yii 2?

Good day to all.
I recently started learning the Yii2 framework.
I'm trying to set up the CNC on Yii 2. I did everything on Google.
But it gives an error.
In config/web.php

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => false,
            'rules' => [

            ],
        ],

Created in the root folder .htaccess
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php

Created .htaccess in the web folder
RewriteEngine On RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

But when accessing the link localhost/test/my/index.php Gives an error.
971260b6b7694ef0bd03fe731139a5a7.png
The folder structure itself:
e7813c2bf04e4dfd9c5999aa041844bf.png
Until I set up the CNC, everything worked with the standard Yii GET request
localhost/test/web/index.php?r=my/index.php
Thank you all in advance for your answers.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-05-18
@maxxtweek

Goodnight.
In the urlManaget rules for the localhost/test address, specify the following:

'rules' => [
     '' => 'my/index'
 ],

at the same time, when you click on the localhost/test link, you will get to the actionIndex() action of the MyController controller
.
<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine on
</IfModule>

<IfModule mod_rewrite.c>
   RewriteCond %{REQUEST_URI} ^/.*
   RewriteRule ^(.*)$ web/$1 [L]

   RewriteCond %{REQUEST_URI} !^/web/
   RewriteCond %{REQUEST_FILENAME} !-f [OR]
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^.*$ web/index.php

</IfModule>

In web .htaccess with content like this
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question