简体   繁体   中英

How do I forbid (403) an entire directory with WordPress .htaccess?

Someone seems to have misspelled a domain name in an image reference at another website. This is causing my website to be slammed with requests for an image that does not exist. My server is not equipped to handle this. It is constantly sending out 404 (not found) responses, maxing my resource usage and making my hosting provider rather upset.

The other website's administrator is unresponsive.

I think I need to send 403 (forbidden) rather than 404 (not found) responses.

The requests my server is receiving look like this:

GET http://www.mywebsite.com/theirdirectoryname/their-file-name.jpg HTTP/1.1

Accordingly I tried to add the following to my .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .*(theirdirectoryname).* - [F]
</IfModule>

This did not work. My server is still responding 404 instead of 403.

Can anyone see what I did wrong?

My server is running WordPress. So there is a WordPress section in my htaccess, as well as a W3TC Browser Cache section, if this makes any difference.

you will prob need your server admin to place the rules for you, most shared accounts ignore .htaccess rules you have.

But there are a couple of different options here,

  1. block the users ip with htaccess (you will find the 1st line already there, place the 2nd line under it)

     Order Deny,Allow Deny from 777.8.3.2 
  2. prevent any leeching of images altogether with apaches httpd.conf file

     SetEnvIfNoCase Referer "^http://www\\.yoururl\\.com/" banimages=1 SetEnvIfNoCase Referer "^http://yoururl\\.com/" banimages=1 SetEnvIfNoCase Referer "^$" banimages=1 <FilesMatch "\\.(gif|png|jpe?g)$"> Order Allow,Deny Allow from env=banimages </FilesMatch> 

I would probably recommend the 2nd, you dont want to be become a content delivery service for the images you have online.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM