Click here for EduSec Demo EduSec Screenshots

Remove index.php in Yii

On 2013-06-10 - By Ravi Thanki

1) Make sure that Apache’s Rewrite Module is enabled.

It can be enabled using a2enmod command:
$ sudo a2enmod rewrite

Then restart Apache like:

root@Roopz-PC:~# /etc/init.d/apache2 restart

2) Set Apache’s ‘AllowOverride’ to ‘ALL’

In my case, I am using virtualhost, so that’s the file I needed to edit. The part I need to edit looks like this:

Options Indexes FollowSymLinks MultiViews
#this is the part that needs changing. Change ‘None’ to ‘All’
AllowOverride None
Order allow,deny
allow from all

Then again, restart the web server.
root@Roopz-PC:~# /etc/init.d/apache2 restart

3) Write the ‘.htaccess’ file in your web application directory

Using your favorite text editor, you may paste this script:

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

4) Edit main.php

Using again your favorite text editor, open the main.php under /protected/config folder. Look for the word ‘urlManager‘ (which is commented by default), and uncomment it if necessary.
The urlManager part of the file I am editing is untouched, so I uncommented it, and configured it in such a way that it now looks like this:

‘urlManager’ => array(
‘urlFormat’ => ‘path’,
‘showScriptName’ => false,
‘rules’ => array(
‘/’ => ‘/view’,
‘//’ => ‘/’,
‘/’ => ‘/’,
),
),

Now you can see

http://localhost/web/site/contact is working :)