Skip to content

How to Remove index.php in the url of Yii Website?

Last updated on February 10, 2018

Usually, when we run a Yii website, the URL will have index.php after the hostname. To remove this in appache web server, we need to enable the mode_rewrite module and should create .htaccess file.

To hide index.php from the url on a website, add an .htaccess file to your web root, with this text:

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

After adding .htaccess, go to /protected/config/ directory open main.php file add 'showScriptName'=>false to urlManager Array

'urlManager'=>array(
			'urlFormat'=>'path',
			'rules'=>array(
				'/'=>'/view',
				'//'=>'/',
				'/'=>'/',
			),
   ),

That’s it you’re Done!

0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments