Well you can use Rewrite Conditions based on %{REMOTE_ADDR}
:
#301 redirect for all pages to use www
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This will redirect only if IP is not equal to 127.0.0.1