Getting variable with $ _GET

1

Hello, in my htaccess it looks like this:

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d

RewriteRule ^(.*)$ index.php?url=$1
RewriteRule ^download/([A-Za-z0-9]+)$ index.php?a=download&k=$1 [QSA,L]

And in download.php

<?php
$k = $_GET['k'];
echo $k;

But this error returns when I access download/?k=aaaa or download/?aaaa

Notice: Undefined index: k

index.php

<body>
    <?php
        require 'config/tratarUrl.php';
        include $pag;
    ?>
</body>

treatUrl.php

<?php
$pUrl = strip_tags(trim(filter_input(INPUT_GET, 'url', FILTER_DEFAULT)));
$sUrl = (empty($pUrl) ? "index" : $pUrl);
$url = array_filter(explode('/', $sUrl));

if (count($url) > 1) 
{
$cont = 1;
foreach ($url as $arg) 
{
    define("PARAM" . $cont, $arg);
    $cont++;
}
} 
else if (count($url) == 1) 
{
if (file_exists(DIR_PAGES . $url[0] . '.php')) 
{
    $pag = DIR_PAGES . $url[0] . '.php';
} 
else 
{
    if($url[0] != 'index')
    {
        $pag = DIR_PAGES . '404.php';
    }
    else
    {
        $pag = DIR_PAGES . 'home.php';
    }
}
} else {
$pag = DIR_PAGES . '404.php';
}
    
asked by anonymous 22.03.2017 / 15:31

1 answer

1

Your rule should contain [QSA,L] .

  

The QSA flag means that it will accept a query string.

     

The L flag means that if the rule matches, it will not process the next string

Change the order of your rule:

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d

RewriteRule ^download/([A-Za-z0-9]+)$ index.php?a=download&k=$1 [QSA,L]
RewriteRule ^(.*)$ index.php?url=$1
22.03.2017 / 16:14