How to set up .htaccess for Kohana correctly, so that there is no ugly "index.php/" in the URL?
Asked Answered
O

6

6

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?

Octopus answered 8/6, 2009 at 19:9 Comment(0)
S
9

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'] = '';
Stroboscope answered 9/6, 2009 at 3:55 Comment(5)
What's the - [F,L] and [PT,L] thing doing?Octopus
See the apache manual: httpd.apache.org/docs/2.2/rewrite/rewrite_flags.html "F|forbidden Using the [F] flag causes Apache to return a 403 Forbidden status code to the client. " "L|last The [L] flag causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed." "PT|passthrough The target (or substitution string) in a RewriteRule is assumed to be a file path, by default."Stroboscope
I've set the index_page to '' in application/config/config.php, and used exactly the same .htaccess. I'm still getting this message when leaving away the index.php/ in my URL: "No input file specified"... very strangeOctopus
I'm not exactly sure, but you could try this thread from the kohana forums. forum.kohanaphp.com/…Stroboscope
That was the solution! I've got a stone old server ;)Octopus
L
5

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.

Linn answered 8/6, 2009 at 21:7 Comment(0)
D
4

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

Deplane answered 8/6, 2009 at 20:58 Comment(2)
It doesn't work. Tried both. config.php has that index_page = ''. Still I can only come to an working controller if I put that index.php/foo inside the URL :/Octopus
Hrm, the "No input file specified" is the exact error that adding the question mark usually fixes. Just to clarify, this fix was for htaccess only, nothing in the config.php file.Deplane
P
2

Try this mod_rewrite rule:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.php index.php%{REQUEST_URI} [L]
Petta answered 8/6, 2009 at 19:12 Comment(2)
And that does what mean? Have you already read kohanaphp.com/tutorials/remove_indexPetta
There comes the "input error" message (white page). Yes, I did. They don't talk about how to remove it, although the title promises it. They totally forgot about it during the article. It's a pitty, really.Octopus
M
1

For those who get "forbidden error" 403 on OSX with default .htaccess be sure to add as the first line in .htaccess

Options +FollowSymLinks

Monadelphous answered 6/3, 2010 at 17:44 Comment(0)
F
0

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.

Flareup answered 17/7, 2012 at 3:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.