WordPress Code Snippets

A fresh mix of code snippets and tutorials

Allow access to external IPs during development


When developing sites, an easy way to keep things private is to use .htaccess to restrict access based on IP address.

To keep your site private during development or maintenance, the following slice of .htaccess works magic:

This denies access to everyone except IP address 123.456.789, so edit that with your own and add the code to your site’s root .htaccess file. Then, to allow for other IP’s, such as that of your mobile ISP, you simply add another “Allow” condition, like so:

And you can add as many IPs as needed to get the job done. For example, I find it useful to allow access to the W3C validators and Gravatar.com (default gravatars don’t work otherwise). I also have a few trusted beta testers for which access is granted. I also make sure that my server’s IP is allowed, to prevent potential conflicts with scripts and such. So when it’s all said and done, my final “development access” code looks something like this:

Note that Gravatar.com changes, so you may need to check your server’s access logs to discover the latest/current IP. Here are some other Gravatar IP addresses:

Further reading

Learn more

.htaccess made easy

Show Support

Like our new Facebook Page to show support!