[英].htaccess rewrite url with get parameters
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 code1 和 code2 正在改变
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. code1 和 code2 工作,但得到没有。
================ I have a test php file like this ================ 我有一个像这样的测试 php 文件
<?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
RewriteRule ^(.*)/(.*)/get$ get.php?c1=$1&c2=$2 [L]
Then you will get the values of c1
and c2
.然后您将获得
c1
和c2
的值。 to get the rest of your values获取您的值的 rest
$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您的页面
get.php
代码应如下所示
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.