.htaccess查询字符串删除-can';我不知道怎么做


.htaccess query string removal - can't figure out how

re,

我不知道如何从URL中删除查询字符串,重定向到另一个URL,并将该查询字符串传递给PHP脚本:

RewriteRule ^shopping/paypal/([0-9A-Za-z]*)?$ https://myserver.com/shopping/? [R=301,L]
RewriteRule ^shopping/$ php/shopping.php [QSA,L]

基本上,当我收到以下请求时:

https://myserver.com/shopping/paypal/?token=EC-3L827812DL640424T

我希望它重定向到:

https://myserver.com/shopping/

由于/shopping/是一个"虚拟"目录,我希望它传递令牌密钥并映射到:

php/shopping.php?token=EC-3L827812DL640424T

请告知。谢谢

我建议您使用这样的中间PHP脚本:

RewriteRule ^shopping/paypal/([0-9A-Za-z]*)?$ php/savetoken.php [QSA,L]
RewriteRule ^shopping/$ php/shopping.php [L]

其中在savetoken.php中:

<?php
    session_start();
    $_SESSION['token'] = $_GET['token'];
    header("HTTP/1.1 301 Moved Permanently"); //without this PHP issues a 302
    header('Location: shopping/');
    exit;

然后在shopping.php中启动会话并从中读取令牌值(可能会将其从会话中删除,以防止将来出现(