4

is it possible to get parameters like: index.php/bar/foo with php? I know that I can use s.th. like index.php?a=bar&b=foo and the user $_GET['a']. But I need to do it with the other way.

gurehbgui
  • 14,236
  • 32
  • 106
  • 178

4 Answers4

5

The answers here just look like guesses. mod_rewrite presumes apache webserver (we don't know which one you use) and is way too much for this simple task.

Apache's default behaviour is to map index.php/xx/xx to index.php?xx/xx.

Look how easy this is:

$args = explode('/', $_SERVER['QUERY_STRING']);

print_r($args);
Daniel W.
  • 31,164
  • 13
  • 93
  • 151
3

EDIT: As DanFromGermany pointed out it is actually possible to have urls like index.php/bar/foo without using mod_rewrite or such. I guess the key here is to have a filename (index.php) in the url.

This has to be done in the web server.

In apache there is a module called mod_rewrite which can rewrite urls like index.php/bar/foo to another format such as index.php?a=bar&b=foo.

Examples, and a description of the topic: http://www.seochat.com/c/a/search-engine-optimization-help/creating-search-engine-friendly-urls-with-php/

What web server are you using?

1

I used following code to access slash parameters:

$args = $_SERVER["REQUEST_URI"];
$arg_arr = explode("/",$args);
print_r($arg_arr);

Hope this helps someone

Mr Megamind
  • 381
  • 2
  • 7
0

To achieve the same either you work on httpd.conf for rewriting the URL or use PHP framework like codeigniter etc. which provide inbuilt functionality.

prashant thakre
  • 5,061
  • 3
  • 26
  • 39