Thanks
Thanks

Reputation: 40329

How can a URL like http://localhost/index.php/articles/edit/1/my-first-article work without an .htaccess?

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?

Upvotes: 3

Views: 8301

Answers (6)

dimo414
dimo414

Reputation: 48824

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, http://example.com/test/my/get/params will not work, while http://example.com/test/index.php/my/get/params will.

Upvotes: 2

SolidSmile
SolidSmile

Reputation: 3206

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.

Upvotes: 1

Tom Haigh
Tom Haigh

Reputation: 57815

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.

Upvotes: 10

Sinan Ünür
Sinan Ünür

Reputation: 118128

See PATH_INFO in CGI Environment Variables.

Upvotes: 0

Ryan Florence
Ryan Florence

Reputation: 13483

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.

Upvotes: 0

Gerry
Gerry

Reputation: 11174

AcceptPathInfo is turned on for your server. :)

Upvotes: 1

Related Questions