IP range in .htaccess file
I want to get access to a IP range with this net feature:开发者_运维百科 68.241.45.0/20 in .htaccess file and in RewriteCond. Something like this:
RewriteCond %{REMOTE_HOST} !^68.241.45.0/20
but it doesn't seem to work.
With RewriteCond
you can only do regular expression or lexicographic comparison. And since 68.241.45.0/20 is the range from 68.241.32.1–68.241.47.254, you could do this:
# regular expression comparison
RewriteCond %{REMOTE_HOST} ^68\.241\.(3[2-9]|4[0-7])\.\d+$
# lexicographic comparison
RewriteCond %{REMOTE_HOST} ^68\.241\.(\d+)\.\d+$
RewriteCond %1 >31
RewriteCond %1 <48
RewriteCond uses regular expression on the second parameter. So you need to escape the dots (.) and use regex for the range.
^68\.241\.[32|47]\.[1|2]?[0-9]+?
精彩评论