大网数据广告活动
网站运营与故障问答

410 response code in subdirectory

· 52CE 我爱测

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/upl…

问题原文

原帖链接 · brandozz · CC BY-SA 3.0

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.

已采纳解答

原帖链接 · MrWhite · CC BY-SA 3.0

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2017-08-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。