apache - X-Robots-Tag 未显示在 HTTP 响应 header 中

标签 apache .htaccess pdf search-engine

我的示例 PDF URL 是: https://askanydifference.com/wp-content/uploads/2022/09/Difference-Between-Import-and-Export.pdf

我正在尝试对我的 WordPress 网站中的所有 PDF 文件建立索引。在进行研究时,我了解到它们只能使用 .htaccess 标记为 noindex,而不能使用任何其他方式,因为 pdf 文件没有任何元标记的 html 代码。

因此,按照下面给出的解决方案,我将 X-Robots-Tag 添加为我的 .htaccess 文件:

https://webmasters.stackexchange.com/questions/14520/how-to-prevent-a-pdf-file-from-being-indexed-by-search-engines

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


# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

<IfModule mod_headers.c>
Header set Content-Security-Policy "block-all-mixed-content"
</IfModule>

我已将 .htaccess 文件放置在 public_html 文件夹中。

但是当我在 Firefox 中检查“网络”选项卡下的文件时,X-Robots-Tag 不存在。

我的所有缓存均已禁用

enter image description here

对我出错的地方有任何帮助

最佳答案

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

您错误地复制了链接的解决方案。将正则表达式与 Files 进行匹配指令您需要额外的 ~争论。 IE。 <Files ~ "\.pdf$"> 。 (尽管在使用正则表达式时 FilesMatch 指令可以说是更好的选择。)

但是,这里不需要正则表达式。只需使用标准 Files具有通配符(非正则表达式)模式的指令。例如:

<Files "*.pdf">
:

引用:

关于apache - X-Robots-Tag 未显示在 HTTP 响应 header 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73760106/

相关文章:

Java:来自资源中pdf文件的inputStream = null

php - XAMPP apache Http 服务器已停止工作

.htaccess - 设置内部 foswiki(只有授权才能查看/编辑)

php - .htaccess URL 重写在 Safari/iPad/iOS 上失败

.htaccess - 在共享托管服务器上使用 codeigniter 感到困惑

javascript - PDF JavaScript 不再在 Edge 中运行

C# - 如何在 : Open PDF, 中突出显示搜索结果,并将突出显示保存回 PDF

php - HTML/PHP 编码,特殊字符在一台服务器上有效,而在另一台服务器上无效

linux - 使用 CentOS 6 对 WHM 进行 DDOS 攻击

apache - 使用 Vagrant 设置 Apache Web 服务器