Removing index.php from Kohana urls

This topic has been covered in just about every website that deals with a php framework. Of course Kohana obeys to this rule so there is a tutorial to remove the index.php part from the url. It is quite thorough although it doesn’t cover the Apache stuff. So here’s a few pointers.

Make sure you run Apache webserver with mod_rewrite enabled (restart Apache after installation) and the AllowOverride directive set ‘All’ and not to ‘None’ in your settings.
Also, make sure you spell .htaccess right.

Please feel free to comment on any common .htaccess pitfalls. I’m no expert in this field so I could do with your help.


2 Responses to “Removing index.php from Kohana urls”

  1. ghaez Says:

    The tutorial .htaccess file doesn’t allow direct connections to images, JS and CSS files placed in /application/views folder. Some developers decide to put their media files outside the /application folder.

    Media controller is a way to solve the problem. But IMO there’s no need to put an additional PHP overload on this.

    Here’s my .htaccess idea of how to deal with the issue easily:

    RewriteEngine On
    RewriteBase /Kohana_folder/
    
    RewriteCond $1 (\.jpg|\.gif|\.png|\.css|\.js)$
    RewriteRule ^(.*)$ - [PT,L]
    
    RewriteCond $1 ^(index\.php|robots\.txt)
    RewriteRule ^(.*)$ - [PT,L]
    
    RewriteCond $1 ^(application|system)
    RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
    
    RewriteRule ^(.*)$ index.php/$1 [PT,L]
    
  2. dlib Says:

    You’re right, if you feel the views directory is the right place for images etc. then your .htaccess is certainly preferred.

Leave a Comment