Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get URL slash/ parameters with simple php?

Tags:

php

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.

like image 704
gurehbgui Avatar asked Oct 30 '25 14:10

gurehbgui


2 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);
like image 55
Daniel W. Avatar answered Nov 01 '25 05:11

Daniel W.


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?

like image 34
David Abrahamsson Avatar answered Nov 01 '25 04:11

David Abrahamsson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!