[英]How to change URL already rewritten with mod_rewrite
I'm trying to modify a RewriteRule for my routing. 我正在尝试为我的路由修改RewriteRule。 I'm using for test this page http://htaccess.mwl.be/ .
我用来测试这个页面http://htaccess.mwl.be/ 。
The request URL is : 请求URL是:
http://myLocalhost.com/backFromPayment/1/?status=CLEARED&amount=1718.21¤cy=USD&description=U900T2351&hash=e805f58f6f96d9ebd4e0ea9da69a37c10704d482&id_sale=8938744
.htaccess rules is: .htaccess规则是:
RewriteRule !^index.php - [C]
RewriteRule (.*) index.php?$0
The output 1 URL is : 输出1的URL是:
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. 此规则适用于所有页面,但对于块“?status = CLEARED&...”,此规则是不够的。
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 : 输出2 URL是:
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 : 输出3的URL是:
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.
但我注意到,当我手动修改URL(复制/粘贴输出3)时,URL工作。
So I must modify this section of .htaccess: 所以我必须修改.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. 在
RewriteRule
的替换部分中添加查询字符串时,此新查询字符串将覆盖任何以前的查询字符串。 If you want to keep the previous query string, add a QSA
flag, eg 如果要保留先前的查询字符串,请添加
QSA
标志,例如
RewriteRule .* index.php?$0 [QSA]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.