Skip to main content
Emphasis on VARIABLE parameter list.
Source Link
lll
  • 12.9k
  • 3
  • 42
  • 60

If its going to be variablethe list of parameters is going to be variable, and you don't want to include separate rules for each case in your htaccess.htaccess file, you might as well just catch the whole query stringquerystring and parse it internally.

You can use something like this RewriteRule ^phpfile.php/(.*)$ phpfile.php?params=$1 (untested), and then in your php file just manually parse the query string like this:

<?php #$_GET['params'] = 'something1-param1/something2-param2/somethin3-param3'; preg_match_all('/(\w+)-(\w+)/', $_GET['params'], $matches, PREG_SET_ORDER); unset($_GET['params']); foreach ($matches as $match) { $_GET[$match[1]] = $match[2]; } unset($_GET['params']);  var_dump($_GET); ?> 

This will set up your $_GET superglobal to contain the key => value pairs as if they had been passed as individual parameters.

If its going to be variable, and you don't want to include separate rules for each case in your htaccess file, you might as well just catch the whole query string and parse it internally.

You can use something like this RewriteRule ^phpfile.php/(.*)$ phpfile.php?params=$1 (untested), and then in your php file just manually parse the query string like this:

<?php #$_GET['params'] = 'something1-param1/something2-param2/somethin3-param3'; preg_match_all('/(\w+)-(\w+)/', $_GET['params'], $matches, PREG_SET_ORDER); unset($_GET['params']); foreach ($matches as $match) { $_GET[$match[1]] = $match[2]; } var_dump($_GET); ?> 

If the list of parameters is going to be variable, and you don't want to include separate rules for each case in your .htaccess file, you might as well just catch the whole querystring and parse it internally.

You can use something like this RewriteRule ^phpfile.php/(.*)$ phpfile.php?params=$1 (untested), and then in your php file just manually parse the query string like this:

<?php #$_GET['params'] = 'something1-param1/something2-param2/somethin3-param3'; preg_match_all('/(\w+)-(\w+)/', $_GET['params'], $matches, PREG_SET_ORDER); foreach ($matches as $match) { $_GET[$match[1]] = $match[2]; } unset($_GET['params']);  var_dump($_GET); ?> 

This will set up your $_GET superglobal to contain the key => value pairs as if they had been passed as individual parameters.

Source Link
lll
  • 12.9k
  • 3
  • 42
  • 60

If its going to be variable, and you don't want to include separate rules for each case in your htaccess file, you might as well just catch the whole query string and parse it internally.

You can use something like this RewriteRule ^phpfile.php/(.*)$ phpfile.php?params=$1 (untested), and then in your php file just manually parse the query string like this:

<?php #$_GET['params'] = 'something1-param1/something2-param2/somethin3-param3'; preg_match_all('/(\w+)-(\w+)/', $_GET['params'], $matches, PREG_SET_ORDER); unset($_GET['params']); foreach ($matches as $match) { $_GET[$match[1]] = $match[2]; } var_dump($_GET); ?>