Rasteril
Rasteril

Reputation: 615

What meaning does the text in the URL have after index.php/

I am wondering what special meaning does text in the URL have after index.php/ So I would have an address like www.site.com/index.php/sometext Is it parsed as a GET parameter, or something else.

I am working on a PHP framework for my personal use. The problem I'm trying to solve is URL routing.

Upvotes: 0

Views: 2125

Answers (3)

anubhava
anubhava

Reputation: 785276

Path after /index.php is available inside your index.php code as:

 $_SERVER["PATH_INFO"]

e.g. for the URL of http://domain.com/index.php/nice/url:

$_SERVER["PATH_INFO"]=/nice/url

This technique is used to create clean/pretty URL in PHP without any support of .htaccess.

Upvotes: 1

Hugo Mota
Hugo Mota

Reputation: 11567

Most frameworks use the text after index.php to route the request without having to rely on ugly query (ex: ?page=foo). So removing the index.php with some .htaccess rule for instance would provide a way to have beautiful urls: site.com/foo/bar. The part after the index.php can be accessed via $_SERVER['PATH_INFO'].

Upvotes: 1

Quentin
Quentin

Reputation: 943643

I am wondering what special meaning does text in the URL have after index.php/

There is no intrinsic special meaning there. Special meaning gets assigned after the first ? and after the first #.

That said, the same script will be run for /index.php and /index.php/foo/bar/baz, and the full URL requested will be available via $_SERVER, so the script can add its own special meaning to it.

See $_SERVER['REQUEST_URI'] and $_SERVER['PATH_INFO'] for some interesting bits. print_r on $_SERVER is also worthwhile.

Upvotes: 2

Related Questions