Send a 404 error via htaccess?

Citizen picture Citizen · Sep 11, 2013 · Viewed 35.4k times · Source

I'd like to cut off access to a subdirectory on my site but I want any access in the subdirectory to be a 404 error, not a 403 forbidden. How can this be accomplished?

Answer

Jon Lin picture Jon Lin · Sep 11, 2013

Try:

RewriteRule ^directory/ - [L,R=404]

This redirects all requests for the folder "/directory/", they get a 404 response.