Password-protect a directory for a range of IP addresses

I've often come across instances where it is very useful to password protect a directory for external visitors, and allow internal visitors to view the directory without authentication. In this post, I'll show you how to easily set this up for multiple ranges of IP addresses.