How to set up .htaccess for Kohana correctly, so that there is no ugly “index.php/” in the URL?
Question
After 2 hours now I couldn't get it right.
The Kohana installation is accessible directly under my domain, i.e. "http://something.org/"
Instead of http://something.org/index.php/welcomde/index I want to have URLs like http://something.org/welcome/index
My .htaccess is messed up completely. It's actually the standard example.htaccess that came with the download. It's almost useless. On the kohana page is a tutorial "how to remove the index.php". It's really useless as well, since it will not even talk about how to remove it. Totally confusing.
Please, can someone provide his working .htaccess for a standard kohana installation?
Solution
My htaccess looks like the example.
RewriteEngine On
RewriteBase /
RewriteRule ^(application|modules|system) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
But you also have to change the config.php file to:
$config['index_page'] = '';
OTHER TIPS
This is our .htaccess file right now, and it seems to be working.
RewriteEngine On
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]
Note that we have our application, system and modules directories all outside of the web root.
On some hosts, I think specficially when running PHP in CGI mode, you have to change
RewriteRule ^(.*)$ index.php/$1 [L]
to
RewriteRule ^(.*)$ index.php?/$1 [L]
in your htaccess. So basically you can use the kohana recommended setup, simply replacing index.php/$1
with index.php?/$1
Try this mod_rewrite rule:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.php index.php%{REQUEST_URI} [L]
For those who get "forbidden error" 403 on OSX with default .htaccess be sure to add as the first line in .htaccess
Options +FollowSymLinks
Kohana 3.2 has a different convention. If you look in Kohana_URL you'll find the following function signature:
public static function site($uri = '', $protocol = NULL, $index = TRUE)
where $index is default to TRUE. By passing a $index FALSE you'll remove the index.php reference.