我的示例 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 文件:
<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 不存在。
我的所有缓存均已禁用
对我出错的地方有任何帮助
最佳答案
<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/