To remove index.php from your URL in Yii 2.* add the following code to {application folder}/web/.htaccess
- RewriteEngine on
- # If a directory or a file exists, use it directly
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- # Otherwise forward it to index.php
- RewriteRule . index.php
And add the following line to configuration file inside the component section
- 'urlManager' => [
- 'class' => 'yii\web\UrlManager',
- 'showScriptName' => false,
- 'enablePrettyUrl' => true,
- '<controller:\w+>/<id:\d+>' => '<controller>/view',
- '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
- '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
- ),
- ],