Enable mod_rewriteon the Apache server and use the rules .htaccessto redirect requests to the controller file.
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ test.php [L]
test.php
$args = explode('/', $_SERVER['REDIRECT_URL']);
array_shift($args);
$data = array();
for ($i = 0; $i < count($args); $i++) {
$k = $args[$i];
$v = ++$i < count($args) ? $args[$i] : null;
$data[$k]= $v;
}
print_r($data);
Accessing the URL http: // localhost / abc / 123 / def / 456 will result in the following:
Array
(
[abc] => 123
[def] => 456
)
source
share