Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache 307 Redirect to redirect POST data

PayPal are annoying...if you have thousands of customer subscriptions which POST IPN's (Instant Payment Notifications) to a certain URL...you can never change that URL. If you want to have the IPN's sent to another URL, their advice...tell all your customers to cancel their subscriptions and start new ones after you've changed the IPN URL. Great.

So after digging around, a solution I found is to use a 307 redirect which will not only redirect to a new URL, but carry along the POST data with it. but I'm having a little trouble with that in Apache. It doesn't seem to work at all. Here is the line in my .htaccess file:

Redirect 307 /index.php?view=account&task=paypal https://api.anotherdomain.com/paypal/ipn

What would be the reason this doesn't redirect?

like image 882
Wasim Avatar asked Apr 15 '26 23:04

Wasim


1 Answers

You can't match against querystring using a Redirec directive. You need to match against %{QUERY_STRING} variable using mod-rewrite. The following rule does what you want :

RewriteEngine on

RewriteCond %{QUERY_STRING} ^view=account&task=paypal$ [NC]
RewriteRule ^/?index\.php$ http://example.com/paypal/? [R=307,L]

? at the end of the destination url is important as it avoids appending old querystring to the new url.

like image 199
Amit Verma Avatar answered Apr 18 '26 17:04

Amit Verma