Hey 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
Try this
A good description is available here
http://www.yiiframework.com/doc/guide/1.1/en/topics.url#hiding-x-23x
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>',
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With