2

I have an htaccess file in one of my subdirectories. I'm trying to throw a 410 response code for .doc and .pdf files in my uploads directory for my multisite installation.

So my .htaccess file is in this directory: wp-content/uploads/sites/2/2016

and looks like this:

RedirectMatch gone "/01/\.pdf$"

So shouldn't this throw a 410 for the following URL:

wp-content/uploads/sites/2/2016/01/my-file.pdf

The full url is currently returning a 404.

1 Answer 1

1
RedirectMatch gone "/01/\.pdf$"

This would match URLs that end in /01/.pdf, so won't match the given URL that ends /01/my-file.pdf.

However, it may be preferable to use mod_rewrite in order to override the standard WordPress directives in the root of the site.

Try the following instead to send a 410 Gone for all .doc and .pdf files in the directory (.htaccess file should be the appropriate subdirectory):

RewriteEngine On
RewriteRule \.(doc|pdf)$ - [G]

UPDATE: If you are still getting a 404 for these resources (which don't exist) then it's possible that you have a custom error document that overrides the HTTP status code. Try resetting this by adding the following before the above directives:

ErrorDocument 410 default
2
  • I placed a .htaccess file in the: wp-content/uploads/sites/2/2016/01/ directory but I'm still not getting a 410. I continue to receive a 404 for any files that used to exist in the directory.
    – brandozz
    Commented Aug 22, 2017 at 1:06
  • What 404 error document is returned? WordPress 404, Apache custom or default document? It's possible you have a defined error document that is overriding the HTTP status? I've updated my answer.
    – MrWhite
    Commented Aug 22, 2017 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.