Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove index.php in Yii Framework

Tags:

url

php

yii

enter image description hereHey guyz i am a newbie in Yii framework. I want to remove the index.php from my urls. Following the yii documentation when i put the rewrite engine code in my .htaccess file and setting showScriptName to false in my config/main.php file i get the 500 internal server error. My .htaccess file is located in root folder of my application. Tell me where i am doing wrong

UPDATE:

This is the code in my .htaccess file:

# 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
like image 206
Code Prank Avatar asked Mar 09 '12 11:03

Code Prank


3 Answers

Try this

A good description is available here

http://www.yiiframework.com/doc/guide/1.1/en/topics.url#hiding-x-23x

like image 151
Akhil Thayyil Avatar answered Nov 03 '22 03:11

Akhil Thayyil


If you also want to remove /index from the main page URL, add ''=>'site/index' to the top of your urlManager rules, like so:

'urlManager'=>array(
    'urlFormat'=>'path',
    'showScriptName' => false,
    'rules'=>array(
        ''=>'site/index',
        '<action>'=>'site/<action>',
like image 6
Samuel Liew Avatar answered Nov 03 '22 03:11

Samuel Liew


taken directly from yii documentation

Hiding index.php There is one more thing that we can do to further clean our URLs, i.e., hiding the entry script index.php in the URL. This requires us to configure the Web server as well as the urlManager application component.

We first need to configure the Web server so that a URL without the entry script can still be handled by the entry script. For Apache HTTP server, this can be done by turning on the URL rewriting engine and specifying some rewriting rules. We can create the file /wwwroot/blog/.htaccess with the following content. Note that the same content can also be put in the Apache configuration file within the Directory element for /wwwroot/blog.

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

We then configure the showScriptName property of the urlManager component to be false.

Now if we call $this->createUrl('post/read',array('id'=>100)), we would obtain the URL /post/100. More importantly, this URL can be properly recognized by our Web application.

Hope this helps, because solved my issue as well.

like image 3
WebDevPT Avatar answered Nov 03 '22 04:11

WebDevPT