I have a url path defined in rewrite rules ('/admin') which I would like to restrict access to only 1 ip address. I'd image the best way would to use .htaccess rather than coding it in. I've tried this but it didn't work. It blocked all urls, not just urls with /admin.
<Location /admin>
Deny from all
Allow from x.x.x.x
</Location>
Location directive is not allowed in .htaccess file. Otherwise, you can add these lines in your Apache configuration file / virtual host file.
You could use RewriteRule's [F] flag to deny the access to all but the permitted IP(s). See the following for an example (I didn't test this but I think it's correct). If you want to use the allow directive, Another way to do it is to use Rewrite directives to set an environment variable using the [E=...] flag of RewriteRule and then do Allow from env=environment_var_goes_here (see http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#allow)
Note: I wrote that example to match any URL starting with /admin, but if you want to just match /admin, remove the .* and replace it with a $.