Updated @Sean's answer for Ack 2
since they removed the two flags that @Sean used
ack 2 release notes say:
The -G option has been removed. Two patterns on the command line was
ambiguous. In this command line:
ack1 -G filepattern -i -w searchpattern
which pattern does -i and -w modify? Now, with ack 2.0, you can use
the new -x to pipe filenames from one invocation of ack into another.
ack2 -g -i filepattern | ack2 -x -w searchpattern
and the -u (unrestricted) flag is not needed any more. So what you want is:
ack -g "\.htaccess" | ack -x pattern
Or, for that matter, just use find to generate the file list (especially useful to find a file in a dotfolder):
find **/.hidden/complex-path/* | ack -x pattern