Yii2 remove index.php from url

When I set the Yii parameter to remove index.php from the URL, I get a 404 error, and this error in the File does not exist: /var/live/var error logs File does not exist: /var/live/var . In my browser I get this error The requested URL /var/decat/frontend/web/index.php was not found on this server. , but the file is located in this place. This may explain that the root of my document is /var/live , and decat is an alias, as shown in the conf file.

This URL works fine http://13.21.16.180/decat/index.php/site/login , but when I delete index.php, I get an error. I followed all the instructions to configure it in a conf file. I even tried through the .htaccess file. Here is the information from my settings file.

 Alias /decat /var/decat/frontend/web <Directory "/var/decat/frontend/web"> # use mod_rewrite for pretty URL support RewriteEngine on # If a directory or a file exists, use the request directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Otherwise forward the request to index.php RewriteRule . index.php Options -Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> 
+7
php yii yii2
source share
5 answers

Add RewriteBase /decat/ after RewriteEngine on and restart apache.

+7
source share

You must install the Url Manager component as follows:

 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, // Only considered when enablePrettyUrl is set to true ], 

Official documents:

+4
source share

yii2 remove web from url

1) Edit your config / web.php file as follows on

 <?php use \yii\web\Request; $baseUrl = str_replace('/web', '', (new Request)->getBaseUrl()); return [ ... 'components' => [ 'request' => [ 'baseUrl' => $baseUrl, ], ... ] ] ?> 

2) Add the following htaccess to root / web

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

3) Add the following htaccess to the root folder in which the application is installed

 # prevent directory listings Options -Indexes IndexIgnore */* # follow symbolic links Options FollowSymlinks RewriteEngine on RewriteRule ^(.+)?$ web/$1 

enter image description here

+3
source share

You must change .htaccess as

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)\?*$ index.php?r=$1 [L,QSA] 

and urlManager rule as

  'urlManager' => [ 'class' => 'yii\web\UrlManager', // Disable index.php 'showScriptName' => false, // Disable r= routes 'enablePrettyUrl' => true, 'rules' => array( '<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', '<controller:\w+>/<action:\w+>' => '<controller>/<action>', ), ], 

I use this in my application. and it works. my url shoes are like www.example.com/user/view?id=1

+2
source share

I think your Apache configuration is wrong ... you say you only rewrite requests for a single character when I read it?

I think it should be:

 RewriteRule ^/(.*) index.php/$1 [L] 

But I could be wrong, not an apache specialist

0
source share

All Articles