我试图为我的路由修改RewriteRule。我正在使用此页面http://htaccess.mwl.be/进行测试。
请求网址为:
http://myLocalhost.com/backFromPayment/1/?status=CLEARED&amount=1718.21¤cy=USD&description=U900T2351&hash=e805f58f6f96d9ebd4e0ea9da69a37c10704d482&id_sale=8938744
.htaccess规则是:
RewriteRule !^index.php - [C]
RewriteRule (.*) index.php?$0
输出1的URL是:
http://myLocalhost.com/index.php?backFromPayment/1/index.php?
此规则适用于所有页面,但适用于块"?status = CLEARED& ......"这个规则是不够的。
所以我评论了以下规则:
#RewriteRule !^index.php - [C]
#RewriteRule (.*) index.php?$0
并添加了这个:
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
输出2网址为:
http://myLocalhost.com/index.php?backFromPayment/1/status/CLEARED/amount/1718.21/currency/USD/description/U900T2351/hash/e805f58f6f96d9ebd4e0ea9da69a37c10704d482/id_sale/8938744
另一项修改如下:
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?
输出3网址为:
http://myLocalhost.com/backFromPayment/1/status/CLEARED/amount/1718.21/currency/USD/description/U900T2351/hash/e805f58f6f96d9ebd4e0ea9da69a37c10704d482/id_sale/8938744
我的修改不起作用。但我注意到,当我手动修改URL(复制/粘贴输出3)时,URL工作。
所以我必须修改.htaccess的这一部分:
RewriteRule !^index.php - [C]
RewriteRule (.*) index.php?$0
如何修改此部分?
答案 0 :(得分:0)
在RewriteRule
的替换部分中添加查询字符串时,此新查询字符串将覆盖任何以前的查询字符串。如果要保留以前的查询字符串,请添加QSA
标记,例如
RewriteRule .* index.php?$0 [QSA]