I am struggling with this .htaccess URL rewrite..?

Viewed 34

I have traffic coming to a WordPress site at https://www.example.com/?edd-listener=IPN

I am trying to rewrite this so that it actually loads https://www.example.com/paypal-ipn-handler.php

I tried this, but it's just loading the WP home page instead of my paypal-ipn-handler.

RewriteEngine On
<IfModule mod_rewrite.c>
RewriteRule /?edd-listener=IPN /paypal-ipn-handler.php [L,NC]
</IfModule>

I can't figure out what adjustment I need to make..??

Any feedback on what I'm doing wrong here would be greatly appreciated. Thanks!

1 Answers

You need to match a query string but RewriteRule only matches URI. Insert this rule just below RewriteEngine On line:

RewriteEngine On

RewriteCond %{QUERY_STRING} (^|&)edd-listener=IPN(&|$) [NC]
RewriteRule ^ /paypal-ipn-handler.php? [L,NC]

# remaining rewrite rules below this line

Note that this will not change URL in browser. If you need that use:

RewriteCond %{QUERY_STRING} (^|&)edd-listener=IPN(&|$) [NC]
RewriteRule ^ /paypal-ipn-handler.php? [L,NC,R=302]
Related