URL rewriting in Yii to hide index.php

Hi Folks,

I am using Yii -yes it is,  MVC framework for new project in PHP.
I started  learning  yii from the official site of yii. I found it is hard to start the work on yii, specially who don’t have
knowledge of MVC framework like Code Igniter (CI) or Zend. It take some time to understand the MVC in yii, as nobody of  us is familler with CI or zend.

Finally we figure out the basics of  Yii. While working on basic of Yii, I want to rewrite the url to SEO friendly.
So I started to search on google, forum got useful information here http://www.yiiframework.com/doc/guide/1.1/en/topics.url

To hide the index.php from url I did changes in config/main.php  as shown below,


and I created new .htaccess file in the same directory as my index.php file shown as below,

RewriteEngine  On
RewriteBase  /
RewriteCond   %{REQUEST_FILENAME} !-f
RewriteCond   %{REQUEST_FILENAME} !-d
RewriteRule    ^(.*)\?*$ index.php/$1 [L,QSA]

 You can change the ”RewriteBase /’  as per project location like if project is located in ‘folder1’ of webroot.
then it change like as    RewriteBase  /folder1

Note that my urlManager has the line:


That will make sure your auto-generated links (CHtml::link or zii.widgets.CMenu) do not have index.php in them. This will not work without the .htaccess file. The reason is that the .htaccess file rewrites the url to point to index.php/$1 so that Yii actually gets the request properly. You will not see the index.php in the url at any time though.

Yii hide index.php from url, geting 404 error

Now it’s time to update this post, While working with Cest Os in local network, I did same thing to rewrite the url.
but it don’t work, the apache rewrite modue is enabled, all things are perfect ,
but still I am geting 404 error while while accessing the page.
After googling couple hours , I found the I have problem in ‘httpd.conf’

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

this allows virtual host rewrite index.

Tagged with: ,
Posted in .htaccess, Yii
3 comments on “URL rewriting in Yii to hide index.php
  1. Johnc91 says:

    I truly appreciate this post. I’ve been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thanks again! geekeecdkeee

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: