I can not figure out the CNC references to yii2. In theory, everything should work, but apparently I’m missing something .... Below are the codes from the project

eshop / .htaccess

Options +FollowSymLinks IndexIgnore */* RewriteEngine on AddDefaultCharset utf-8 RewriteCond %{REQUEST_URL} !^/(web) RewriteRule ^assets/(.*)$ /web/assets/$1 [L] RewriteRule ^css/(.*)$ /web/css/$1 [L] RewriteRule ^fonts/(.*)$ /web/fonts/$1 [L] RewriteRule ^js/(.*)$ /web/js/$1 [L] RewriteRule ^images/(.*)$ /web/images/$1 [L] #RewriteRule (.*)$ /web/$1 RewriteRule ^(.*)?$ /web/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /web/index.php 

eshop / web / .htaccess

 #RewriteBase / RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php 

eshop / config / web

 .... 'request' => [ // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation 'cookieValidationKey' => 'uvxfBK9B1S8ovnPJGbcAYyRrRCj56Qh3', 'baseUrl' => '', ], ... 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ 'category/<id:\d+>/page/<page:\d+>' => 'category/view', 'category/<id:\d+>' => 'category/view', 'product/<id:\d+>' => 'product/view', 'search' => 'category/search', ], ], ... 

Regular links without CNC work, that is, if I follow the link http: //yii2.loc/eshop/web/index.php? R = category% 2Fview & id = 4, then I see elements from the selected category, but when I activate the CNC, the link acquires the view http: //yii2.loc/eshop/web/category/4 appears Object not found!

and when loading the start page

enter image description here

Tell me what am I doing wrong?

  • And on the link http://yii2.loc/eshop/web/category/4 what is displayed? - P. Fateev
  • no, only Object not found! - Ildar Nasurlaev

1 answer 1

In your case, you need to be sure to specify baseUrl

 'components' => [ 'request' => [ 'baseUrl' => '', ], ], 

just put in the root .htaccess

 RewriteRule ^(.*)?$ /web/$1 [L] 

and remove from the second file

 RewriteBase / 

better replace it with

 RewriteEngine on 
  • Added changes as you advised and introduced amendments to the topic, but some kind of evil rock is going on again Object not found! - Ildar Nasurlaev
  • one
    I just noticed that you have a project in the eshop folder? but why?) the fact is that the baseUrl is set just to the directory where the project is located. in your case, of course, you need to set 'baseUrl' => '/ eshop' and in this case the project will be available at yii2.loc / eshop no need for any web (with my settings) - WebCoder
  • one
    and don't forget to fix .htaccess with / eshop too - WebCoder
  • Thank you so much bro helped to remove the eshop folder and it all worked! - Ildar Nasurlaev