How to change the ? character in the PHP query string into / character?
Mar 15th, 2008 17:57
ha mo, Dan Zambonini, Penton Wong,
This will need to be configured outside of PHP - in fact, within the
If you're using Apache, you can use Mod Rewrite
(http://httpd.apache.org/docs/mod/mod_rewrite.html) or even the Files
directive (http://httpd.apache.org/docs/mod/core.html#files) within
an .htaccess file.
If you're using IIS, you'll need to pay for a solution; an easy to use,
good value solution (in my experience) is IIS Rewrite
Depending on which solution you use, you'll have to adapt your PHP
files accordingly. Mod rewrite will be easiest (from the PHP side of
things) - it can automatically convert the requested /a/b/c URL to the
appropriate _GET variables.
The Files directive can simply redirect any requests from a specific
location (e.g. anything under /a/*, e.g. /a/b/c/d or /a/f/g) to a PHP
script (e.g. /a.php). Your PHP script will then - from the original
HTTP request variables, decode back into the _GET values.
IIS Rewrite is similar to the Files directive, only it creates a new
global variables during the process, that you can query for the values.
Note that you'll also have to adapt the 'output' from your PHP -
perhaps a global output catching script, that converts all your
internal query string (?a=b&c=d) URLs into the nice /a/b/c/d URLs -
with a handy regular expression or two.