1

I am trying to prevent a bot from accessing certain file extension within a public directory on our server. We use Apache and I wish to apply a .htaccess rule to prevent the bot from being able to access that particular extension file type from the directory. I tried looking for a snippet related to this but could not find one.

We are right now using the following code to prevent the bot from accessing the directory. The following .htaccess is placed in that particular directory.

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} BotName [NC]
RewriteRule ^ - [R=403,L]

Now we wish to ensure that the bot is able to access the directory but not certain files (file extension type) in the directory.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • If you search for "ban user agent" in this site, there are many duplicates. – halfer Jul 01 '19 at 18:32
  • IMO, the proposed duplicate does not cover the question. The question asks how to block "*certain file extensions*" for a specific user agent. The duplicate just blocks a matching user agent from all access and does not appear to touch on limiting it to blocking "certain file extensions". It's probably a duplicate, but it's not a duplicate of the proposed duplicate-target alone. – Makyen Jul 01 '19 at 23:28
  • @Makyen: good spot. [This question does not have an answer](https://stackoverflow.com/questions/7958372/htaccess-stop-a-php-redirect), but it shows the right technique - testing `REQUEST_URI` and `HTTP_USER_AGENT`. The only minor difference is that the `[OR]` would not be used. – halfer Jul 02 '19 at 07:32
  • If readers do not want to close as a duplicate, Too Broad would be fine - there is a reasonable expectation of effort here, so: user5621919, please get searching too, find some mod_rewrite config, and try it. You can then edit it into your question, showing what it did (not) do. – halfer Jul 02 '19 at 07:35
  • @halfer Appreciate your prompt response and help on this. I'll be updating the question and try to make it more easy for every body to understand with the steps which we already took. Thank you! –  Jul 04 '19 at 06:23
  • @Makyen I have edited the question. Please take a look. I am also referring to the other question suggested by you meanwhile. –  Jul 04 '19 at 06:26
  • I would guess you just need another `RewriteCond`, but this time on the `REQUEST_URI` variable. Try it, and update your question with the results. – halfer Jul 04 '19 at 07:43

0 Answers0