I'm trying to modify a RewriteRule for my routing. I'm using for test this page http://htaccess.mwl.be/ .
The request URL is :
http://myLocalhost.com/backFromPayment/1/?status=CLEARED&amount=1718.21¤cy=USD&description=U900T2351&hash=e805f58f6f96d9ebd4e0ea9da69a37c10704d482&id_sale=8938744
.htaccess rules is:
RewriteRule !^index.php - [C]
RewriteRule (.*) index.php?$0
The output 1 URL is :
http://myLocalhost.com/index.php?backFromPayment/1/index.php?
This rule works for all pages but for the chunk "?status=CLEARED& ... " this rules is not sufficient.
So I commented below rules:
#RewriteRule !^index.php - [C]
#RewriteRule (.*) index.php?$0
and added this one:
RewriteCond %{QUERY_STRING} status=(\w+)&amount=(\w+\.{1}\w*)¤cy=(\w+)&description=(\w+)&hash=(\w+)&id_sale=(\d+)
RewriteRule ^(.*)$ /index.php?$0status/%1/amount/%2/currency/%3/description/%4/hash/%5/id_sale/%6
The Output 2 URL is :
http://myLocalhost.com/index.php?backFromPayment/1/status/CLEARED/amount/1718.21/currency/USD/description/U900T2351/hash/e805f58f6f96d9ebd4e0ea9da69a37c10704d482/id_sale/8938744
Another modification is as follows :
RewriteCond %{QUERY_STRING} status=(\w+)&amount=(\w+\.{1}\w*)¤cy=(\w+)&description=(\w+)&hash=(\w+)&id_sale=(\d+)
RewriteRule ^backFromPayment/1/ http://%{HTTP_HOST}/backFromPayment/1/status/%1/amount/%2/currency/%3/description/%4/hash/%5/id_sale/%6?
The output 3 URL is :
http://myLocalhost.com/backFromPayment/1/status/CLEARED/amount/1718.21/currency/USD/description/U900T2351/hash/e805f58f6f96d9ebd4e0ea9da69a37c10704d482/id_sale/8938744
My modifications doesn't work. But I noticed that when I modified the URL manually (copy/paste output 3) the URL works.
So I must modify this section of .htaccess:
RewriteRule !^index.php - [C]
RewriteRule (.*) index.php?$0
What to do to modify this section?
When you add a query string in the substitution part of the RewriteRule
, this new query string overwrites any previous query string. If you want to keep the previous query string, add a QSA
flag, eg
RewriteRule .* index.php?$0 [QSA]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.