On the hosting is installed yii2-basic , installed not in the root, but in htdocs/basic .

I want to replace http://домен/basic/web/about with http://домен/basic/about .

At the moment, the last address redirects to the main page.

In basic lies the following .htaccess :

 <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 basic/web there is also .htaccess :

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

In config/web.php :

 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ '' => 'site/index', '<action>'=>'site/<action>', ], ], 

In 'request' adding 'baseUrl' => '' gives 404.

  • Not banned. The method above did not work - Tarasovych
  • Try this in the rules 'basic/about' => 'basic/web/about' - Alexey
  • You probably meant 'basic/web/about' => 'basic/about' , but it doesn't work ( - Tarasovych
  • 'baseUrl' => 'basic' - Urmuz Tagizade
  • @ilyaplot, i.e. Questions that have an answer on the toaster is not the place here? - vp_arth

1 answer 1

I myself have often come across clients who have had regular hosting, where it was not possible to register the root directory.

Here is how I solved this problem:

1) At the root of the project, create a .htaccess with the contents:

Illustrative example

 <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On </IfModule> <IfModule mod_rewrite.c> RewriteCond %{REQUEST_URI} ^/.* RewriteRule ^(.*)$ basic/web/$1 [L] RewriteCond %{REQUEST_URI} !^/basic/web/ RewriteCond %{REQUEST_FILENAME} !-f [OR] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ basic/web/index.php </IfModule> 

2) In the web folder, create a .htaccess with the contents:

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

3) Next, open the config / web.php file and do the following:

Find the line

 'request' => [ 'cookieValidationKey' => ......., ], 

And add the line 'baseUrl' => '' to the array

 'request' => [ 'cookieValidationKey' => ......., 'baseUrl' => '', ], 

4) I rush ahead and write how to remove index.php

Find a line in the config / web.php file

 'urlManager' => [ ........ //остальная часть кода ], 

And add the line 'showScriptName' => false to the array

 'urlManager' => [ 'showScriptName' => false, ........ //остальная часть кода ], 

This instruction is relevant for the folder structure you specified. Usually the project is poured into the root of the site. In this case, we remove the basic in the first paragraph and enjoy life :)

  • does not work - crashes layout. I will seek solutions further ... - Tarasovych
  • Carefully everyone looked and did? 1 point especially - Urmuz Tagizade