0

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.

Rasteril
  • 605
  • 1
  • 5
  • 16

3 Answers3

2

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.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Is there any way to see what the user has typed into the space, even though it has no meaning at first? – Rasteril Feb 27 '13 at 16:56
1

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'].

Hugo Mota
  • 11,200
  • 9
  • 42
  • 60
1

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.

anubhava
  • 761,203
  • 64
  • 569
  • 643