.htaccess X-Robots-标记未显示在HTTP响应标头中

8e2ybdfx  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(199)

我的示例PDF URL是:https://askanydifference.com/wp-content/uploads/2022/09/Difference-Between-Import-and-Export.pdf
我试图在我的WordPress网站上noindex我所有的PDF文件。在做研究时,我了解到,他们只能使用.htaccess标记noindex,而不是任何其他方式,因为PDF文件没有任何HTML代码的 meta标记。
因此,通过下面给出的解决方案,我将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不存在。
我的所有缓存都已禁用

有没有人能帮我找出我的错误

z6psavjg

z6psavjg1#

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

您错误地复制了链接的解决方案。若要将正则表达式与Files指令匹配,您需要额外的~参数。即<Files ~ "\.pdf$">。(尽管可以论证,在使用正则表达式时,FilesMatch指令更可取。)
但是,这里不需要正则表达式。只需使用带有 * 通配符 *(不是正则表达式)模式的标准Files指令。例如:

<Files "*.pdf">
:

参考编号:

  • https://httpd.apache.org/docs/current/mod/core.html#files
  • https://httpd.apache.org/docs/current/mod/core.html#filesmatch

相关问题