Freedom To Learn ……….

Writing, to me, is simply thinking through my fingers. — Isaac Asimov

URL rewriting in Yii to hide index.php

1 Comment

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,

‘urlManager’=>array(
                              ‘urlFormat’=>’path’,
                              ‘showScriptName’=>false,
                              ‘rules’=>array(
                                                ‘<controller:\w+>/<id:\d+>’=>'<controller>/view’,
                                               ‘<controller:\w+>/<action:\w+>/<id:\d+>’=>'<controller>/<action>’,
                                              ‘<controller:\w+>/<action:\w+>’=>'<controller>/<action>’,
                                             ),
), 

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:

‘showScriptName’=>false,

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.

About these ads

Author: gaurishpatil

PHP Developer..

One thought on “URL rewriting in Yii to hide index.php

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.