views:

716

answers:

6

I don't get this:

http://localhost/index.php/articles/edit/1/my-first-article

This URL is mentioned as an example in the Kohana framework documentation. I poked around in the files of my installation, and there is no .htaccess besides my own one that has nothing to do with that.

So, how can it be that an index.php is called but then, as parameters, the stuff looks like added directories to the URL? That doesn't look "real".

Or is this just how native PHP/Apache/HTTP stuff actually works? As I understand it, / is always telling "hey, a directory!". Makes really zero sense to me... how's that possible? Or do they have somewhere an .htaccess that I just can't see / find?

+9  A: 

From the Apache docs:

AcceptPathInfo Directive

This directive controls whether requests that contain trailing pathname information that follows an actual filename (or non-existent file in an existing directory) will be accepted or rejected. The trailing pathname information can be made available to scripts in the PATH_INFO environment variable.

For example, assume the location /test/ points to a directory that contains only the single file here.html. Then requests for /test/here.html/more and /test/nothere.html/more both collect /more as PATH_INFO.

So I assume this setting is enabled somewhere like in httpd.conf. Note that this, like mod_rewrite, can be enabled/configured in a number of places - see here.

Tom Haigh
+1  A: 

AcceptPathInfo is turned on for your server. :)

Gerry
+2  A: 

In PHP you can get the data after the filename with the $_SERVER["PATH_INFO"] variable. This allows you to basically GET information without having to use GET variables, which means Google and co will think you're using static pages. This is basically an alternative to mod_rewrite which is often enabled while mod_rewrite is more often not enabled.

This may be obvious to you, but it wasn't immediately to me, this doesn't work correctly on index pages unless you use the filename. For instance, example.com/test/my/get/params will not work, while example.com/test/index.php/my/get/params will.

dimo414
A: 

Probably not the case here, and certainly not recommended, and probably not the right answer...

BUT ...

I've seen people use 404 pages to parse the request and then include the right page with that information.

rpflo
A: 

See PATH_INFO in CGI Environment Variables.

Sinan Ünür
+1  A: 

I'm not using Kohana, so I don't know if my method will be of any use, but when a server doesn't support .htaccess files (or rewrite rules) my 'framework' generates URI's like this:

http://www.domain.com/?/articles/edit/1/my-first-article (notice the ?)

It's a similar method used by the Frog framework, just parse $_SERVER['REQUEST_URI'] (or $_SERVER['HTTP-X-REWRITE-URL'] on windows servers) and explode on the '/'.

This method is completely rewrite independent and still generates more-or-less SEO friendly URI's

Hope it's of any use to you.

SolidSmile