htaccess正则表达挑战

发布于 2025-02-02 07:09:03 字数 940 浏览 2 评论 0原文

我正在尝试写一个.htaccess的正则表达式,但仍然无法做到。我花了很多时间试图弄清楚道路。当然,使用正则是,很难找到一个确切的答案。这就是为什么我真的很感谢您的帮助。

场景是:有一个脚本(WordPress插件)向我的API网关提出了帖子请求,看起来像:

https://example.com/?edd_action=check_license&item_id=111&license=UN_222&url=some.url.com

一切都在起作用,但是我的结局有一个API更新,现在它不会执行它。 但是,在进行了多次测试之后,我发现同一请求在执行方式时可以工作:

https://example.com/wp-admin/admin-ajax.php?edd_action=check_license&item_id=111&license=UN_222&url=some.url.com

因为有很多人安装了WordPress插件,并且他们的许可证被停用了,所以他们无法进行自动更新,而唯一的方法是重定向向将使插件活动的请求。

要解决的问题是我们如何从以下方式重定向邮政请求:

https://example.com/?edd_action=check_license&item_id=111&license=UN_222&url=some.url.com

使用:

https://example.com/wp-admin/admin-ajax.php?edd_action=check_license&item_id=111&license=UN_222&url=some.url.com

使用HTACCESS REGEX规则。

关于如何解决这个问题的任何想法?

I'm trying to write an .htaccess regex, but still can't make it. I spent many hours trying to figure out the way. Of course, with regex, it is hard to find an exact answer. That's why I would really appreciate your help.

The scenario is: there is a script (WordPress plugin) making a POST request to my API gateway which looks like:

https://example.com/?edd_action=check_license&item_id=111&license=UN_222&url=some.url.com

Everything was working, but there was an API update on my end and now it won't execute it.
However, after doing multiple tests, I discovered that the same request works when executed this way:

https://example.com/wp-admin/admin-ajax.php?edd_action=check_license&item_id=111&license=UN_222&url=some.url.com

Because there are many people who have installed the WordPress plugin and their license was deactivated, they cannot do an automatic update, and the only way is to redirect the request to the one that will make their plugin active.

The problem to be solved is how we can redirect post requests from:

https://example.com/?edd_action=check_license&item_id=111&license=UN_222&url=some.url.com

to:

https://example.com/wp-admin/admin-ajax.php?edd_action=check_license&item_id=111&license=UN_222&url=some.url.com

Using htaccess regex rules.

Any ideas on how to approach this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高冷爸爸 2025-02-09 07:09:03

您可以在.htaccess的顶部尝试此重定向规则:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^edd_action=check_license&item_id=[^&]+&license=[^&]+&url=[^&]+$ [NC]
RewriteRule ^$ /wp-admin/admin-ajax.php [L,R=302,NE]

# other WP .htaccess code goes below this

如果给出的查询字符串模式成功地匹配,则将将URI重定向到/wp-admin/admin-ajax.php

You can try this redirect rule at top of your .htaccess:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^edd_action=check_license&item_id=[^&]+&license=[^&]+&url=[^&]+$ [NC]
RewriteRule ^$ /wp-admin/admin-ajax.php [L,R=302,NE]

# other WP .htaccess code goes below this

This rule will redirect landing page URI to /wp-admin/admin-ajax.php if given query string pattern matches successfully.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文