Removing index.php from URL in YiiFramework 2.0

To hide the ‘index.php’ and enable the Pretty URL in yiiframework 2.0, this post will help you. For this we have to configure the .htaccess and web.php file.

.htaccess

Please add the following lines in ‘.htaccess’ file inside the ‘web’ directory of yii2.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(
					
				),
		],
	.................