【问题标题】:how to redirect URL containing query string and random numbers in .htaccess如何在.htaccess中重定向包含查询字符串和随机数的URL
【发布时间】:2017-11-05 23:11:05
【问题描述】:

当客户在我的网站上取消交易时,他们会被重定向到 WooCommerce 购物车页面,查询字符串末尾包含随机生成的数字。

例子

https://www.example.com/cart/?woo-paypal-cancel=true&token=EC-5474842406066680S

(由于激活了 CDN 的 WP Rocket 缓存与 WooCommerce 之间存在插件冲突,我需要此重定向。长篇大论。)

我想知道我究竟会在我的.htaccess 文件中放入什么以使其重定向到

https://www.example.com/cart/

我尝试了在 Stackpath 上的多个页面上找到的多种变体,但它没有重定向。显然我错过了一些东西,所以我求助于大师。

非常感谢您的帮助。

【问题讨论】:

  • 你应该展示你所尝试的。什么是“堆栈路径”?

标签: .htaccess url redirect query-string


【解决方案1】:

要将/cart/?woo-paypal-cancel=true&token=<anything> 重定向到/cart/,您可以在.htaccess 文件顶部附近尝试以下操作(使用mod_rewrite):

RewriteEngine On
RewriteCond %{QUERY_STRING} ^woo-paypal-cancel=true&token=
RewriteRule ^cart/$ /cart/? [R,L]

RewriteRule 末尾的? 替换 会从请求中去除查询字符串。

这是一个临时 (302) 重定向。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    • 2021-04-05
    • 1970-01-01
    • 2014-05-07
    • 1970-01-01
    • 2014-07-08
    相关资源
    最近更新 更多