.htaccess查询字符串删除 - 无法弄清楚如何

时间:2011-09-21 15:52:35

标签: php .htaccess mod-rewrite

重,

我无法弄清楚如何从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

请指教。谢谢!

1 个答案:

答案 0 :(得分:0)

我建议您使用这样的中间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中启动会话并从中读取令牌值(并可能从会话中删除它,以防止它在将来弹出)