Reputation: 31
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?
Upvotes: 2
Views: 41
Reputation: 786111
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.
Upvotes: 2