The REDIRECT_QUERY_STRING
is generated exclusively by .htaccess
and will only get querystring, REQUEST_URI
will get the URL + querystring.
Note that REDIRECT_QUERY_STRING
is something that is being generated at each internal redirect (rewriting), so it can generate something like REDIRECT_REDIRECT_QUERY_STRING
and then REDIRECT_REDIRECT_REDIRECT_QUERY_STRING
, depending on how many redirections it takes.
What you can do to ease is simply to pass as a GET parameter, like this:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ ?PATH=$1 [L]
And in PHP I'd get it like this (php7):
define('UA', explode('/', $_GET['PATH'] ?? ''));
In php5:
define('UA', explode('/', empty($_GET['PATH']) ? '' : $_GET['PATH']));
PHP_SELF
Another way to avoid controlling the PATH
parameter would be to use the PHP_SELF
combined with parse_url
, first the HTACCESS should look like this:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^ index.php [L]
So PHP should look like this:
$path = parse_url($_SERVER['PHP_SELF'], PHP_URL_PATH); //isto irá remover a querystring do sufixo
define('UA', explode('/', $path));
Of course, $_SERVER['PATH_INFO']
, but I believe that PATH_INFO is not standard and may vary (depending on the version of Apache, in this case I recommend that you use even PHP_SELF
combined with parse_url
.
In case the result of UA
to teste.com/produto/iphone-7-64gb/35
will be something like:
Array
(
[0] =>
[1] => produto
[2] => iphone-7-64gb
[3] => 35
)
Note that [0]
is empty, this is because the PATH of a URL always starts with /
, so to avoid it you can simply use ltrim
or substr
, for example:
$path = parse_url($_SERVER['PHP_SELF'], PHP_URL_PATH); //isto irá remover a querystring do sufixo
define('UA', explode('/', ltrim($path, '/')));