.htaccess rewrite url with get parameters

Viewed 31

I am trying to rewrite something like that.

http://127.0.0.1/code1/code2/get?a=8&q=7

code1 and code2 is changing

http://127.0.0.1/get.php?c1=code1&c2=code2&a=8&q=7

I have tried much things such as

RewriteEngine On
RewriteRule ^get\.php$ - [L]
RewriteRule ^([^/]+)\/([^/]+)\/get?(.*)$ /get.php?c1=$1&c2=$2&$3 [L]

The code1 and code2 working but the get not.

================ I have a test php file like this

<?php
echo $_GET['c1']."<br>";
echo $_GET['c2']."<br>";
echo $_GET['a']."<br>";
echo $_GET['q']."<br>";
?>

And that is what I receive.

code1
code2


1 Answers
RewriteRule ^(.*)/(.*)/get$ get.php?c1=$1&c2=$2 [L]

Then you will get the values of c1 and c2. to get the rest of your values

$katorymnd_uxqn  = explode("&", explode("?", $_SERVER['REQUEST_URI'])[1] );
print_r($katorymnd_uxqn);

Giving you array of your remaining values

Array ( [0] => a=8 [1] => q=7 ); 

Your page get.php code should look like this

echo $_GET['c1']."<br>";
echo $_GET['c2']."<br>";


$katorymnd_uxqn  = explode("&", explode("?", $_SERVER['REQUEST_URI'])[1] );

$katorymnd_ldba = array();
$katorymnd_ldba[] = $katorymnd_uxqn;

print explode('=', $katorymnd_ldba[0][0], 2)[1]."<br>";
print  explode('=', $katorymnd_ldba[0][1], 2)[1]."<br>";

Now you get all the values as expected.

code1
code2
8
7
Related