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.

migrated from wordpress.stackexchange.com Aug 22 '17 at 2:48

This question came from our site for WordPress developers and administrators.

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
  • 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 Aug 22 '17 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 Aug 22 '17 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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