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

How to prevent a specific PDF file from being indexed by search engines in Wordpress?

· 52CE 我爱测

In a wordpress multisite installation, I would like to block indexing of a specific pdf file using HTTP X-Robots-Tag response header using htaccess file. Any of the indications found in previous related questions (i.e. this one )…

问题原文

原帖链接 · bobrock4 · CC BY-SA 4.0

In a wordpress multisite installation, I would like to block indexing of a specific pdf file using HTTP X-Robots-Tag response header using htaccess file.

Any of the indications found in previous related questions (i.e. this one) didn't work in my case.

I used the instructions but all checks and every online checkers don't shows the headers I'd need

These are my htaccess configs

These are real headers in browser inspector

已采纳解答

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

The <Files> directive only applies to filenames, not file-paths, so your <Files> directive will never match and the header will not be set.

To set this header on a specific file (and not all .pdf files - as in the linked question/answers) in the root .htaccess file then you can set an environment variable when this file is requested and conditionally set the header based on this env var.

For example:

SetEnvIf Request_URI "/path/to/example.pdf" NOINDEX
Header set X-Robots-Tag "noindex, nofollow" env=NOINDEX

Alternatively, if you could place an additional .htaccess file in the directory that contains the PDF file you want to target, then you could use a <Files> directive in that .htaccess file:

<Files "example.pdf">
Header set X-Robots-Tag "noindex, nofollow"
</Files>

You could use this same method in the root .htaccess file, but it will also add the header to all example.pdf file requests on the system - although it's probably unlikely you have more than one file with the same name anyway I would think, so this may be the better solution after all.

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

资料来源与适用范围

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

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

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