.htaccess block outside access on local server except for certain URL's
.htaccess, apache
Solution
You can use `mod_rewrite` based rules instead in your root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} !/paypal_ipn [NC]
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteRule ^ - [F]
This will block all requests that are not:
- originating from localhost (`127.0.0.1`)
- for `/paypal_ipn`
Problem
I currently have my local `.htaccess` on a MAMP server set up to block all incoming traffic from outside my local system; ``` <FilesMatch ".*"> Order deny,allow Deny from all Allow from 127.0.0.1 </FilesMatch> ``` This works fine but I then use API's like PayPal that require access to your site for IPN's. Is it possible to keep the restriction on the rest of the site and allow outside access only to specific urls like `https://example.com/paypal_ipn`? I understand I can just switch the restriction off when using IPN's but that's not what I'm looking for. Many thanks.