Reputation: 11265
What I actually want to do:
Trying to write in .htaccess rules:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^1.1.1.1 [OR]
RewriteCond %{REMOTE_ADDR} !^2.2.2.2 [OR]
RewriteCond %{REMOTE_ADDR} !^3.3.3.3 [OR]
RewriteCond %{REMOTE_ADDR} !^4.4.4.4 [OR]
RewriteCond %{REMOTE_ADDR} !^127.0.0.1
RewriteCond %{REQUEST_URI} !^/example/test$
RewriteRule ^(.*)$ app.php [R=403,L]
Condition in pseudo code looks like
IF REMOTE_ADDR IS NOT (1.1.1.1 OR 2.2.2.2 OR 3.3.3.3 OR 4.4.4.4 OR 127.0.0.1) AND REQUEST_URI IS NOT /example/test THEN ACCESS DENIED
.htaccess
file is valid and condition looks like logic, where can be problem, because in every request I get 403
response
(IP address are not real, I'm changed to fake for security reason)
Upvotes: 0
Views: 924
Reputation: 18671
Use:
RewriteEngine On
RewriteRule ^example/test$ - [L]
RewriteCond %{REMOTE_ADDR} !^1\.1\.1\.1
RewriteCond %{REMOTE_ADDR} !^2\.2\.2\.2
RewriteCond %{REMOTE_ADDR} !^3\.3\.3\.3
RewriteCond %{REMOTE_ADDR} !^4\.4\.4\.4
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteRule ^ - [F,L]
RewriteRule ^ app.php [L]
Upvotes: 1
Reputation: 1462
RewriteEngine On
# Allow /example/test
RewriteCond %{REQUEST_URI} ^/example/test$
RewriteRule ^ - [L]
# Allow access to rest of the site to 5 IPs
RewriteCond "%{REMOTE_ADDR}" "!=1\.0\.0\.1"
# Example IP6 address
RewriteCond "%{REMOTE_ADDR}" "!=::2"
RewriteCond "%{REMOTE_ADDR}" "!=3\.3\.3\.3"
RewriteCond "%{REMOTE_ADDR}" "!=4\.4\.4\.4"
RewriteCond "%{REMOTE_ADDR}" "!=5\.5\.5\.5"
RewriteRule ^ - [R=403,L]
# Arrive to app.php
RewriteRule .? app.php [L]
Upvotes: 2