Wednesday, March 30, 2011

How to hide index.php in the url in a Yii website

to hide "index.php" from the url on a website, add an .htaccess file to your web root, with this text:

Options +FollowSymLinks
IndexIgnore */*
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

and in /protected/config/main.php, set:


'urlManager'=>array(
'urlFormat'=>'path',
   'showScriptName'=>false,
   'caseSensitive'=>false,

4 comments:

  1. i am not able to find webroot in apache .
    plz help me out where is the exactly location.

    ReplyDelete
    Replies
    1. Web root is your project directory.

      for example if your project is in /var/www/myproject

      you need to put the .htaccess file under your webroot means /var/www/myproject/.htacess

      I hope this helps.

      http://www.webnapps.co.uk

      Delete
  2. Excellent and straight to the point!

    I found another resource on the web, this is what I used: http://macinville.com/119/remove-indexphp-in-yii-web-application/

    ReplyDelete