We are getting rid of some spammy inbound links to our site. This means we want to have these links resolve as '404 not found'. I am having problems sorting out the basic .htaccess modification needed to do this.
I want any links starting with 'www.example.com/cgi-bin/dir' to give a 404 code, thus I added this to my .htaccess in the www directory:
RewriteRule ^cgi-bin/dir.*$ - [L,R=404]
I got to this line of code by combining the answers to this and this question. It works fine on 'www.example.com/cgi-bin/dir' itself, but does not work for any link lower down the directory. Non-working links include links like 'http://www.example.com/cgi-bin/dir/search.cgi'. There is no .htaccess file in the cgi-bin folder, or the relevant subfolders.
Any ideas?