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
My Answer:
You can use the following code in your .htaccess file to rewrite the URL with get parameters:
RewriteEngine On
RewriteRule ^code1/code2/get$ index.php?a=8 [L]
This will rewrite the URL http://127.0.0.1/code1/code2/get?a=8 to index.php with the parameter a=8.
Rate this post
4 of 5 based on 1220 votesComments