March 04, 2015

March 04, 2015
In this article, we are going to discuss about how to remove the index.php from the URL (enable search engine friendly SEF URL) in YII php framework. We can get the SEF url by removing the index.php from the URL. If you are using YII framework you are noticed that by default index.php will be included with your URL. In this article I am going to explain about How to remove the index.php from the YII framework site URL.

By removing the index.php from the URL we can get the site URL like below

To acheive this, follow the below steps.


Please add the following lines in '.htaccess' file inside the 'web' directory of YII 2.0 application.

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

Configuration of Web.php File

By default 'config/web.php' file does not have a option 'urlManager'. If we want to enable a pretty url, We have to add and configure the 'urlManager' in 'web.php' file.

To remove the 'index.php' from url, we have to the 'showScriptName' value as false.

To remove the 'r' route variable from url, set the 'enablePrettyUrl' value as true.

'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(



Post a Comment