How to block all accesses, except three IPs, to an absolute URL with htaccess?
Example data: http://subdomain.example.com/url/i/want/to/block IPs: 10.10.10.10 10.10.10.11 10.10.10.12
This is my code:
RewriteCond %{REQUEST_URI} http://subdomain.example.com/url/i/want/to/block
RewriteCond %{REMOTE_ADDR} !=10.10.10.10
RewriteCond %{REMOTE_ADDR} !=10.10.10.11
RewriteCond %{REMOTE_ADDR} !=10.10.10.12
RewriteRule ^.*$ /index.php [R=302,L]
and it's not working. I'm accessing the URL with any IP.
You can't match protocol
and port etc in REQUEST_URI
. Have it this way:
RewriteCond %{HTTP_HOST} =subdomain.example.com
RewriteCond %{REMOTE_ADDR} !=10.10.10.10
RewriteCond %{REMOTE_ADDR} !=10.10.10.11
RewriteCond %{REMOTE_ADDR} !=10.10.10.12
RewriteRule ^url/i/want/to/block /index.php [R=302,L,NC]
Or using regex character class:
RewriteCond %{HTTP_HOST} =subdomain.example.com
RewriteCond %{REMOTE_ADDR} !^10\.10\.10\.1[0-2]$
RewriteRule ^url/i/want/to/block /index.php [R=302,L,NC]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.