Friday 18 July 2014

How to hide index.php from url in yii

URL rewriting in Yii to hide index.php

To hide the index.php from url you have to make the changes in config/main.php  as shown below,
‘urlManager’=>array(
                              ‘urlFormat’=>’path’,
                              ‘showScriptName’=>false, //this option will be hide the index.php from url
                              ‘rules’=>array(
                                                ‘<controller:\w+>/<id:\d+>’=>’<controller>/view’,
                                               ‘<controller:\w+>/<action:\w+>/<id:\d+>’=>’<controller>/<action>’,
                                              ‘<controller:\w+>/<action:\w+>’=>’<controller>/<action>’,
                                             ),
), 
and create 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 ‘abc/′ of webroot.
then it change like as    RewriteBase  /abc

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.

No comments:

Post a Comment

List OF BANK PAN Numbers

List OF BANK PAN Numbers Bank/Home Loan Providers PAN Number Allahabad Bank AACCA8464F Andhra Bank AABCA7375C Axis Bank...