【问题标题】:X-Robots-Tag not shown in HTTP response headerX-Robots-Tag 未显示在 HTTP 响应标头中
【发布时间】:2022-09-24 20:45:25
【问题描述】:

我的示例 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 is my .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 中的 Network 选项卡下检查文件时,X-Robots-Tag 不存在。

我所有的缓存都被禁用

关于我哪里出错的任何帮助

    标签: apache .htaccess pdf search-engine


    【解决方案1】:
    <Files "\.pdf$">
      Header set X-Robots-Tag "noindex, nofollow"
    </Files>
    

    您错误地复制了链接的解决方案。要将正则表达式与 Files 指令匹配,您需要额外的 ~ 参数。 IE。 &lt;Files ~ "\.pdf$"&gt;。 (虽然FilesMatch 指令在使用正则表达式时可以说是更可取的。)

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

    <Files "*.pdf">
    :
    

    参考:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-21
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 2013-07-29
      • 1970-01-01
      • 2021-05-17
      相关资源
      最近更新 更多