Home » Linux » Remove index.php from Yii Framework URL

Remove index.php from Yii Framework URL

First important point is that
Module_Rewrite is enabled on your server(LAMP,WAMP,XAMP..etc)
For do URL rewiring in yii2 framework Create one .htaccess file and put in /web folder

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

second step
config folder common/config/main-local.php
add to components array

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

Leave a Reply


Check Also

How to get desktop files in ubuntu terminal

smarttips@smart-System-Product-Name:~/Desktop$ cd /home/<username>/Desktop Example:marttips@smart-System-Product-Name:~/Desktop$ cd /home/smarttips/Desktop