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?

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Thanks
  • 40,109
  • 71
  • 208
  • 322

6 Answers6

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'] = '';
Ambirex
  • 811
  • 4
  • 9
  • What's the - [F,L] and [PT,L] thing doing? – Thanks Jun 09 '09 at 08:39
  • See the apache manual: http://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." – Ambirex Jun 09 '09 at 13:22
  • 1
    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 strange – Thanks Jun 09 '09 at 16:43
  • 1
    I'm not exactly sure, but you could try this thread from the kohana forums. http://forum.kohanaphp.com/comments.php?DiscussionID=1245&page=1#Item_24 – Ambirex Jun 09 '09 at 22:19
  • That was the solution! I've got a stone old server ;) – Thanks Jun 09 '09 at 23:19
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.

davidtbernal
  • 13,434
  • 9
  • 44
  • 60
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

Dylan
  • 144
  • 1
  • 7
  • 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 :/ – Thanks Jun 09 '09 at 17:13
  • 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. – Dylan Jun 09 '09 at 19:20
2

Try this mod_rewrite rule:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.php index.php%{REQUEST_URI} [L]
Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • And that does what mean? Have you already read http://kohanaphp.com/tutorials/remove_index – Gumbo Jun 08 '09 at 20:03
  • 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. – Thanks Jun 08 '09 at 20:29
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

Marcin Ignac
  • 59
  • 1
  • 4
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.

Henry Tseng
  • 3,263
  • 1
  • 19
  • 20