Redirect PayPal IPN with .htaccess

While working on a customer account, we had to redo the whole membership system to work with a new system and still support the Paypal reccuring billing. However, we had a previous system that was using the recurring billing and relying on IPN set in PayPal to update the membership inside the module. Now that we had a new system with different folder structure, the previous recurrent payment created with the old system were stuck on the old IPN url in PayPal , seems this is a PayPal security setting of some sort,  you can’t change the IPN url on previously set recurrent billing.

Basically we needed to support those old recurrent billing in the new system to avoid users from cancelling the recurrent billing and creating a new one. We had to simply redirect the old IPN to the new one but keeping the post data coming from PayPal.

After searching for a while, we come up with something very simple using Proxy method with Apache.

First you need to make sure the mod_proxy is enable on your server. If you have SSH access and root rights, type the following command:

a2enmod proxy
a2enmod proxy_http

Then restart apache to get the new mod enabled.

/etc/init.d/apache2 restart

Now go edit your .htaccess file with the following lines:

<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^/path-to-old-IPN/IPN.php [NC]
RewriteRule ^.*$ [P]

Obviously you need to replace the path and file name above with yours. Basically we are telling any url getting in the root webfolder followed by the old IPN path, simply pass it to apache via a Proxy method, so the server requesting the page don’t see any difference as apache is serving the new IPN instead of the old one.

This doesn’t simply applied to PayPal but to any other service using IPN or actually anything you want to redirect using proxy method.

Leave Your Response

* Name, Email, Comment are Required