简体   繁体   English

如何重定向包含.htaccess中的查询字符串和随机数的URL

[英]how to redirect URL containing query string and random numbers in .htaccess

When customers cancel a transaction on my site, they get redirected to the WooCommerce cart page with a query string containing randomly generated numbers at the end. 当客户在我的网站上取消交易时,他们将被重定向到WooCommerce购物车页面,该查询字符串的末尾包含随机生成的数字。

Example

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

(I need this redirect due to a plugin conflict between WP Rocket cache with CDN activated and WooCommerce. Long story.) (由于激活CDN的WP Rocket缓存和WooCommerce之间存在插件冲突,因此我需要此重定向。)

I'm wondering what exactly I would put in my .htaccess file to get it to redirect to 我想知道我将在.htaccess文件中放什么以使其重定向到

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

I've tried a number of variations I found on multiple pages here on Stackpath, but it wasn't redirecting. 我已经尝试过在Stackpath的多个页面上找到的多种变体,但是没有重定向。 Obviously I'm missing something so I'm turning to the gurus. 显然,我缺少了一些东西,所以我转向大师。

Would be very grateful for your help. 非常感谢您的帮助。

To redirect /cart/?woo-paypal-cancel=true&token=<anything> to /cart/ you can try something like the following near the top of your .htaccess file (using mod_rewrite): 要将/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]

The ? ? on the end of the RewriteRule substitution strips the query string from the request. RewriteRule 替换的末尾,将从请求中剥离查询字符串。

This is a temporary (302) redirect. 这是临时(302)重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM