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.
4 Answers
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);

- 31,164
- 13
- 93
- 151
-
1Very good information, thank you! I just tried it on my local installation and it worked. – David Abrahamsson Aug 07 '14 at 13:39
-
DanFromGermany: This is just out of curiosity: what happens if you have an url like http://mysite/index/bar/foo? Then you would have to use mod_rewrite or something similar, right? – David Abrahamsson Aug 07 '14 at 13:44
-
@DavidAbrahamsson Yes, when you want to hide the `.php` and other things you need to use `mod_rewrite`. – Daniel W. Aug 07 '14 at 13:47
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?

- 326
- 1
- 5
-
Ah okay thank you. I'm using a apache webserver. But this ansers my question, because I just wanted to know if its possible with pure php – gurehbgui Aug 07 '14 at 13:21
-
check the htaccess for this kind of url rewrite http://stackoverflow.com/a/12229240/2706194 – user2706194 Aug 07 '14 at 13:22
-
Apache's default behaviour is to map `index.php/xx/xx` to `index.php?xx/xx`. – Daniel W. Aug 07 '14 at 13:32
I used following code to access slash parameters:
$args = $_SERVER["REQUEST_URI"];
$arg_arr = explode("/",$args);
print_r($arg_arr);
Hope this helps someone

- 381
- 2
- 7
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.

- 5,061
- 3
- 26
- 39