Answer the question
In order to leave comments, you need to log in
Why is Yii2 CNC not working?
I am learning the Yii2 basic framework. And it seems like everything is fine, but the CNC did not work at the start, and then I decided to give up on this problem and study further, but now I decided to return.
The webserver I am using is wamp64.
The site is in the site folder.
And that root directory is localhost/site/web
I uncommented
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
RewriteEngine On
RewriteRule ^(.+)?$ /web/$1
RewriteBase /
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule . index.php
http://localhost/site/web/site/contact
Answer the question
In order to leave comments, you need to log in
Rename the site directory, come up with a name for this local project, because in views there is a site directory that the SiteController controller accesses.
Let the new name be mysite.
In this directory you will place your entire yii2 project.
Then, in the root of your project, put .htaccess with the following content:
<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>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
use \yii\web\Request;
$baseUrl = str_replace('/web', '', (new Request)->getBaseUrl());
return [
'components' => [
'request' => [
'baseUrl' => $baseUrl,
],
],
];
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'' => 'site/index'
],
],
localhost/mysite
, you will have to open the main page of your project, without "web" in the address bar.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question