1

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


2
  • "The code1 and code2 working but the get not." - of course not, because RewriteRule matches against the path component of the URL, and not the query string. If you wanted to match or capture something in the latter - you need to do so using a RewriteCond. Commented Aug 25, 2022 at 6:02
  • But if you just want to merge the original query string with the newly created one - use the QSA flag. Commented Aug 25, 2022 at 6:04

1 Answer 1

1
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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.